[R] ggplot seq

Felipe Carrillo mazatlanmexico at yahoo.com
Fri Jan 23 16:19:55 CET 2009


Thanks Thierry: 
The use of levels is what I needed, thanks for your help.




 From: ONKELINX, Thierry <Thierry.ONKELINX at inbo.be>
 Subject: RE: [R] ggplot seq
 To: mazatlanmexico at yahoo.com, r-help at stat.math.ethz.ch
 Date: Friday, January 23, 2009, 3:01 AM
 Dear Felipe,
 
 Provide a dummy sample if your dataset is big or
 confidential. The actual values are not that important to figure out what
 kind of plot you want.
 How did you code Week? Numeric? Try convert it into a
 factor with levels = c(27:52, 1:26). And then set the breaks to seq(1, 52, by= 2).
 
 WFBox <- data.frame(Week = rep(1:52, 10), FL = rnorm(520))
 WFBox$fWeek <- factor(WFBox$Week, levels = c(27:52, 1:26))
 library(ggplot2)
 ggplot(WFBox, aes(fWeek, FL)) + geom_boxplot(outlier.colour="pink",outlier.size=3,outlier.shape=21,fill=
 "goldenrod",colour="blue") + scale_x_discrete(breaks=c(seq(1,51,2)))
 
 HTH,
 
 Thierry
 
  ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Research Institute
 for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
 methodology and quality assurance
 Gaverstraat 4 9500 Geraardsbergen
 Belgium 
tel. + 32 54/436 185
 Thierry.Onkelinx at inbo.be  www.inbo.be 
> Onderwerp: [R] ggplot seq
> 
> I have dealt with this before and I can't remember how
> it got resolved.
> It is too much data to reproduce the example below(49.000
> records) but
> all I am after is trying to get the x axis breaks. I want
> my x axis to
> go from 27 to 51 and 1 to 25 by 2. I am trying to
> concatenate the breaks
> but it sorts the seq() in ascending order. Is there a way
> to workaround
> it? see scale_x_continuous below:
> 
> boxP <- ggplot(WFBox, aes(Week, FL,group=Week))
> boxP +
> geom_boxplot(outlier.colour="pink",outlier.size=3,outlier.shape=21,fill=
> "goldenrod",colour="blue") +
> scale_x_discrete(breaks=c(seq(27,51,2),seq(1,25,2)))
> 
> Felipe D. Carrillo  
> Supervisory Fishery Biologist  
> Department of the Interior  
> US Fish & Wildlife Service  
> California, USA




More information about the R-help mailing list