[R] ggplot2 X axis levels

Felipe Carrillo mazatlanmexico at yahoo.com
Wed Feb 24 16:32:17 CET 2010

Thanks Dieter, I actually adopted your example but I
thought it would be an easy way to order non-factor data.

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA

----- Original Message ----
> From: Dieter Menne <dieter.menne at menne-biomed.de>
> To: r-help at r-project.org
> Sent: Sat, February 20, 2010 2:56:14 AM
> Subject: Re: [R] ggplot2 X axis levels

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).


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,
> 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))

winter$week1 <- seq(as.Date("2000-07-01"), 
> length.out=52, by="1 
> week")

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

> ymailto="mailto:R-help at r-project.org" 
> href="mailto:R-help at r-project.org">R-help at r-project.org mailing list
> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank 
> >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.

More information about the R-help mailing list