[R] ggplot2 X axis levels

Dieter Menne dieter.menne at menne-biomed.de
Sat Feb 20 11:56:14 CET 2010



Felipe Carrillo wrote:
> 
> Hi all:
> I've done this before with factors but can't figure how to do it with
> a continuous variable. I am trying to reorder the sequence of my weeks
> along the X axis. I want to start with week 27 to 52 and then 1 to 26.
> I guess I could use levels along with seq() but doesn't seem to work for
> me.
> 
> 

Thanks for the nice example. I would suggest instead of weeks with
modulo-handling, you use dates, and one of the formatting functions for date
axis (not shown here).

Dieter

winter <- structure(list(week = c(27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 52L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L), BY_2008 = c(95L, 77L, 124L, 159L, 2376L,
9480L, 17314L, 99574L, 323679L, 198211L, 93630L, 129183L, 111820L,
71260L, 35241L, 14020L, 20778L, 21694L, 15016L, 13400L, 9187L,
3607L, 2804L, 2417L, 5291L, 16216L, 898L, 558L, 709L, 972L, 61L,
372L, 3086L, 10108L, 4295L, 882L, 2593L, 36L, 233L, 243L, 0L,
70L, 272L, 308L, 134L, 40L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("week",
"BY_2008"), class = "data.frame", row.names = c(NA, -52L))

library(ggplot2)
winter$week1 <- seq(as.Date("2000-07-01"), length.out=52, by="1 week")
qplot(week1,BY_2008,data=winter,geom="line",colour=I('blue'),size=I(1))

-- 
View this message in context: http://n4.nabble.com/ggplot2-X-axis-levels-tp1562155p1562746.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list