[R] Odp: Newbie on plotting

Petr PIKAL petr.pikal at precheza.cz
Mon Feb 11 17:07:44 CET 2008


Hi

r-help-bounces at r-project.org napsal dne 08.02.2008 22:00:36:

> Hi...
> 
> I am issuing a: plot(x,y), where x is a factor.
> i expect a box-and-whisker plot and I do get it.
> The data is 'bucketed' into 10 buckets on the x-axis.
> When I process some data, I get data in buckets 1,7,8,9 and 10.
> Problem is when I plot it, it shows only those buckets on the x-axis.
> if I subsequently do a points(4,3,pch-16) for example, it places the
> point not at x=4, but at x=9. It's as if R kind of forgot the scaling.

The position of boxes depends on levels of your factor. If you did

my.box <- boxplot(something)

you can look to my.box how your boxplot is really described. Based on what 
you have said your processed data have factor for x axis only with 
mentioned levels. If you want to keep all levels, you need to modify your 
processing to do it, or you can add missing levels and order them 
according to your wish.

x <- sample(1:10, 200, replace=T)
x[x>3 & x<6] <- NA

xx <- factor(x)
levels(xx) <- c(levels(xx),4,5)
plot(xx, rnorm(200))
ooo <- order(as.numeric(levels(xx)))
plot(factor(xx, levels=levels(xx)[ooo]), rnorm(200))

Regards
Petr

> 
> What am I doing wrong here? I really would like 0-10 to appear
> on the xaxis and I can't seem to get this to work.
> 
> Joe
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list