Re: [R] boxplot via plot command
Antje niederlein-rstat at yahoo.de writes: I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Just to complete my response, the documentation for plot.data.frame indicates For a two-column data frame it plots the second column against the first by the most appropriate method for the first column. kk -- Ken Knoblauch Inserm U846 Institut Cellule Souche et Cerveau Département Neurosciences Intégratives 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr __ R-help@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.
Re: [R] boxplot via plot command
Hi, thank you both for your response. I don't want to do anything like this - I just got some code like this from someone else and was wondering about the result. I would have used another approach to create a boxplot like this... Ciao, Antje [EMAIL PROTECTED] schrieb: hi: i'm not well versed in the OO mechanism behind R but you've created a dataframe with one column being factors so, when the plot command sees this, there must be code in the plot generic that decided that the best thing to use is a boxplot. I'm not sure what you want since you have 3 factors but below is a guess ? I split by the factor and then plot the values seperately with the colors denoting the factors ? if it's not what you want, then i would resend your question to the list explaining what you do want because there are others on this list that can probably help you more than i can. good luck. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(l=as.factor(l), x) print(df) print(str(df)) temp - split(df,df$l) plot(temp[[1]]$x,ylim=c(min(temp[[1]]$x,temp[[2]]$x,temp[[3]]$x), max(temp[[1]]$x,temp[[2]]$x,temp[[3]]$x)),col=green) lines(temp[[2]]$x,type=p,col=blue) lines(temp[[3]]$x,type=p,col=red) On Tue, Dec 2, 2008 at 3:30 AM, Antje wrote: Hi folks, I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Thank you! Antje __ R-help@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@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.
Re: [R] boxplot via plot command
Hi, Antje niederlein-rstat at yahoo.de writes: Hi folks, I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Thank you! Antje You can follow this through the various methods. If you look at plot.data.frame getAnywhere(plot.data.frame) You'll see that when the data.frame has only 2 columns, it calls plot with the first two arguments. Since the first argument here is a factor, it dispatches to the plot.factor method getAnywhere(plot.factor) from which you'll see that under your circumstances it will call boxplot HTH, Ken __ R-help@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] boxplot via plot command
Hi folks, I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Thank you! Antje __ R-help@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.