[R-sig-teaching] graphing inequalities (intervals) in one varible
R. Michael Weylandt
michael.weylandt at gmail.com
Thu May 9 12:49:19 CEST 2013
Here's the start of a function. I'll leave it to you to do it better
(it should probably also use S4 methods, but that's another project):
interval <- function(lower = -Inf, upper = Inf, lower_closed = FALSE,
upper_closed = FALSE){
structure(.Data = NULL, lower = lower, upper = upper, lower_closed =
lower_closed, upper_closed = upper_closed, class = 'interval')
}
plot.interval <- function(x){
l <- attr(x, "lower")
u <- attr(x, "upper")
r <- c(l, u) * c(if(l > 0) 0.7 else 1.2, if(u > 0) 1.2 else 0.7)
plot(r, c(0,1), main = '', bty = 'n', xlab = '', ylab = '', yaxt =
'n', type = 'n', xaxt = 'n')
axis(1, at = seq(r[1], r[2], length.out = 10))
lines(c(l, u), c(0.5, 0.5), col = 2, lwd = 2)
lc <- attr(x, 'lower_closed')
uc <- attr(x, 'upper_closed')
points(c(l, u), c(0.5, 0.5), pch = c(1, 19)[c(lc, uc) + 1], col = 2, cex = 2)
}
On Wed, May 8, 2013 at 12:10 PM, Yahoo! <aboueiss at yahoo.com> wrote:
> Dear All:
>
> It seems a very silly question. But I never tried it before. I am teaching a college algebra class this summer.
>
> I need some help with graphing intervals on the real line. For examples:
>
> {x | -7<= x < 5 and x > 7}
>
> {x | x > 3}
>
> etc...
>
>
> thank you very much
> abou
>
> ========================
>
> AbouEl-Makarim Aboueissa
>
> Sozan Elsalakawy
>
> Mohamed Agamia
>
>
>
> 246 Auburn Street, #158
>
> Portland, ME 04103
>
> USA
>
>
>
> Tel: (207) 797-2724
>
> Email: aboueiss at yahoo.com
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
More information about the R-sig-teaching
mailing list