[R] ggplot seq

Felipe Carrillo mazatlanmexico at yahoo.com
Fri Jan 23 18:44:27 CET 2009


Actually 'levels' works OK by ordering the x axis labels but since I have 52 weeks it gets too crowded.
Here's part of my dataset with a reproducible example.

sampDat <- "Week  FryPassage
27 665
28 2232
29 9241
30 28464
31 41049
32 82216
33 230411
34 358541
35 747839
36 459682
37 609567
38 979475
39 837189
40 429016
41 523436
42 304785
43 125005
44 28047
45 5141
46 7503
47 2273
48 1065
49 0
50 0
51 0
52 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0"
WFBar <- read.table(textConnection(sampDat), header = TRUE)
WFBar
# Bar graph (option # 1)
    options(scipen=3)
bargraph <- qplot(factor(Week,levels=c(27:52,1:26)),FryPassage,
data=WFBar,geom="bar",fill=I("grey65"),colour=I("goldenrod"),
  ylab="Numb of Fish",xlab="Week")
   bargraph # levels give me the desired X axis order but it is too crowded
   
     # Bar graph (option # 2) If I skip levels then I don't get to see the bars for the skipped levels
    options(scipen=3)
    WFBar$Week <- factor(WFBar$Week,levels=c('27','29','31','33','35','37','39','41','43','45','47','49','51','1','5','10','15','20','25'))
bargraph <- qplot(WFBar$Week,FryPassage,data=WFBar,geom="bar",fill=I("grey65"),colour=I("goldenrod"),
  ylab="Numb of Fish",xlab="Week")
   bargraph
   # It seems that thickmarks is what I need here. I was trying to concatenate c(seq(27,51,2),seq(1,25,2)) like someone else
   #suggested but this doesn't seem to work with scale_x_continuous(breaks= c(seq(27,51,2),seq(1,25,2))).
   # So, my question here is: How can I use the seq() function to create my custom thick marks along the x axis (same order
   # as the WFBar object skipping one week in between?



--- On Fri, 1/23/09, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:

> 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




More information about the R-help mailing list