An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090329/c9644bbc/attachment-0002.pl>
a loop for boxplot graphs
3 messages · James Lenihan, Coen van Hasselt
You could use the paste() function to dynamically assign label values.
For instance, like this:
dat<-data.frame(id=1:4,x=1:4,y=1:4)
par(mfrow=c(2,2))
for (i in dat$id){
boxplot(dat$x[dat$id==i],
dat$y[dat$id==i],
main=paste("Results for Subject",i) )
}
There might be a better answer though- e.g. avoiding a for-loop.
Coen
On Mon, Mar 30, 2009 at 07:08, James Lenihan <jameslenihan at sbcglobal.net> wrote:
Dear Colleagues I have the following code that generates a boxplot for?one specific labtest: boxplot.n(LBSTRESN~COHORT, main="Boxplot of laboratory data for XLXXX-XXX test=Creatinine", subset = LBTEST=="Creatinine", xlab = "Cohort Number", ylab = "Units = umol/L", varwidth=TRUE I would like to know if there is a way to loop through the dataset and produce the boxplot for a number of?specific labtest. Looking at the documentation for loops I can't see how I would change the "ylab","main"and "subset" Can someone refer me to a similar example in the online documentation? Thanks, Jim?L ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ 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.
Oops, the example only accounts for 1 observation, so better do
something like this in that case:
..
for (i in unique(dat$id)){
..
On Mon, Mar 30, 2009 at 07:50, Coen van Hasselt
<coenvanhasselt at gmail.com> wrote:
You could use the paste() function to dynamically assign label values.
For instance, like this:
dat<-data.frame(id=1:4,x=1:4,y=1:4)
par(mfrow=c(2,2))
for (i in dat$id){
boxplot(dat$x[dat$id==i],
? ? ? ? ?dat$y[dat$id==i],
? ? ? ? ?main=paste("Results for Subject",i) )
}
There might be a better answer though- e.g. avoiding a for-loop.
Coen
On Mon, Mar 30, 2009 at 07:08, James Lenihan <jameslenihan at sbcglobal.net> wrote:
Dear Colleagues I have the following code that generates a boxplot for?one specific labtest: boxplot.n(LBSTRESN~COHORT, main="Boxplot of laboratory data for XLXXX-XXX test=Creatinine", subset = LBTEST=="Creatinine", xlab = "Cohort Number", ylab = "Units = umol/L", varwidth=TRUE I would like to know if there is a way to loop through the dataset and produce the boxplot for a number of?specific labtest. Looking at the documentation for loops I can't see how I would change the "ylab","main"and "subset" Can someone refer me to a similar example in the online documentation? Thanks, Jim?L ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ 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.