[R] ask help about boxplot , different list variation into the tick of x-axis?

John Kane jrkrideau at yahoo.ca
Fri Jul 31 00:33:26 CEST 2009


Replying to my own post, it occurred to me that there is a simple solution using the reshape package. Here's an example using some made-up data.
#=====================================================================
years  <- 1997:2008
set.seed <- 1234
(mydata <- data.frame(matrix(rnorm(60, 25, 5),ncol=5), years))

library(reshape)
newdata  <- (melt(mydata, id=c("years")))
boxplot(value~years, data=newdata)

#======================================================================

--- On Thu, 7/30/09, John Kane <jrkrideau at yahoo.ca> wrote:

> From: John Kane <jrkrideau at yahoo.ca>
> Subject: Re: [R] ask help about boxplot , different list variation into the tick of  x-axis?
> To: r-help at r-project.org, "Jie TANG" <totangjie at gmail.com>
> Received: Thursday, July 30, 2009, 6:18 PM
> 
> You are trying to apply a funtion to a data.frame that is
> intended to work on a vector that is indexed on another
> vector.   
> 
> Try pasting this into R to see what I mean
> 
> boxplot(len ~ dose, data = ToothGrowth)
> ToothGrowth
>  
> 
> --- On Thu, 7/30/09, Jie TANG <totangjie at gmail.com>
> wrote:
> 
> > From: Jie TANG <totangjie at gmail.com>
> > Subject: [R] ask help about boxplot , different list
> variation into the tick of  x-axis?
> > To: r-help at r-project.org
> > Received: Thursday, July 30, 2009, 5:54 PM
> >  Hi ,everyone.
> > 
> > I want to draw a boxplot figure, main script shown as
> > below. when I
> > run the command "boxplot(bjavee~yearname)",it is wrong
> with
> > the error
> > information " model.frame.default(formula = bjavee ~
> > yearname) :
> >   variation 'bjavee' list is wrong".
> > 
> > I want to add the yearname as the x-axis tick. And
> yearname
> > is a array
> > with the length 12,while bjavee is a 5*12 matrix. How
> could
> > I get what
> > I want? thanks.
> > 
> > bjerr1<-bjerrdata$tyerr[1:bjyearnum[2]]
> >
> bjerr2<-bjerrdata$tyerr[(bjyearnum[2]+1):bjyearnum[3]]
> >
> bjerr3<-bjerrdata$tyerr[(bjyearnum[3]+1):bjyearnum[4]]
> >
> bjerr4<-bjerrdata$tyerr[(bjyearnum[4]+1):bjyearnum[5]]
> >
> bjerr5<-bjerrdata$tyerr[(bjyearnum[5]+1):bjyearnum[6]]
> >
> bjerr6<-bjerrdata$tyerr[(bjyearnum[6]+1):bjyearnum[7]]
> >
> bjerr7<-bjerrdata$tyerr[(bjyearnum[7]+1):bjyearnum[8]]
> >
> bjerr8<-bjerrdata$tyerr[(bjyearnum[8]+1):bjyearnum[9]]
> >
> bjerr9<-bjerrdata$tyerr[(bjyearnum[9]+1):bjyearnum[10]]
> >
> bjerr10<-bjerrdata$tyerr[(bjyearnum[10]+1):bjyearnum[11]]
> >
> bjerr11<-bjerrdata$tyerr[(bjyearnum[11]+1):bjyearnum[12]]
> >
> bjerr12<-bjerrdata$tyerr[(bjyearnum[12]+1):length(bjerryear)]
> > 
> > bjavee<-data.frame(5,12)
> > cprob=c(0.05,0.25,0.5,0.75,0.95)
> > bjavee[1:5,1]<-quantile(bjerr1,prob=cprob)
> > bjavee[1:5,2]<-quantile(bjerr2,prob=cprob)
> > bjavee[1:5,3]<-quantile(bjerr3,prob=cprob)
> > bjavee[1:5,4]<-quantile(bjerr4,prob=cprob)
> > bjavee[1:5,5]<-quantile(bjerr5,prob=cprob)
> > bjavee[1:5,6]<-quantile(bjerr6,prob=cprob)
> > bjavee[1:5,7]<-quantile(bjerr7,prob=cprob)
> > bjavee[1:5,8]<-quantile(bjerr8,prob=cprob)
> > bjavee[1:5,9]<-quantile(bjerr9,prob=cprob)
> > bjavee[1:5,10]<-quantile(bjerr10,prob=cprob)
> > bjavee[1:5,11]<-quantile(bjerr11,prob=cprob)
> > bjavee[1:5,12]<-quantile(bjerr12,prob=cprob)
> > 
> > 
> > yearname<-(1997:2008)
> > 
> > png(file=".\\png\\jptrkfivenum24.png",
> bg="transparent")
> > 
> >
> bjbox<-data.frame(bjavee[1:5,1],bjavee[1:5,2],bjavee[1:5,3],bjavee[1:5,4],bjavee[1:5,5],bjavee[1:5,6],bjavee[1:5,7],bjavee[1:5,8],bjavee[1:5,9],bjavee[1:5,10],bjavee[1:5,11],bjavee[1:5,12])
> > boxplot(bjavee~yearname)
> > 
> > ______________________________________________
> > 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.
> > 
> 
> 
>      
> __________________________________________________________________
> Looking for the perfect gift? Give the gift of Flickr! 
> 
> http://www.flickr.com/gift/
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/




More information about the R-help mailing list