[R] Odp: Newbie on plotting

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Mon, 11 Feb 2008 17:07:44 +0100

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.



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. Received on Mon 11 Feb 2008 - 16:14:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Feb 2008 - 16:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive