[R] Help me please: gplot, facets_wrap and ordering of x axis dates

David Lyon david_lyon3 at yahoo.com
Wed May 15 14:49:18 CEST 2013


Thanks John for your reply.
I did include the data if you scroll down to the end of my original email.

Can someone help me on this? 

Thanks




----- Original Message -----
From: John Kane <jrkrideau at inbox.com>
To: David Lyon <david_lyon3 at yahoo.com>; r-help <r-help at r-project.org>
Cc: 
Sent: Tuesday, May 14, 2013 4:11 PM
Subject: RE: [R] Help me please: gplot, facets_wrap and ordering of x axis
  dates

Thank you for supplying the code. It would be easier to help you  if we also had some data to work with.  ?dput

https://github.com/hadley/devtools/wiki/Reproducibility

I think reorder() is likely to do the trick but I don't have enough time to mock up some data and check at the moment.

Have a look at  http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot

Good luck.
John Kane
Kingston ON Canada


> -----Original Message-----
> From: david_lyon3 at yahoo.com
> Sent: Tue, 14 May 2013 12:59:07 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Help me please: gplot, facets_wrap and ordering of x axis
> dates
> 
> I have a text file of data as below and doing a ggplot line plot of all
> the ids as separate mini line plots which works with the following code.
> 
> Problem how do I order the dates for each id plot on the x axis so that
> the dates are going from oldest to most recent????
> 
> 
> Thanks in advance
> 
> Dave
> 
> 
> 
> 
> 
> CODE:
> 
> a<-read.table("DATA",header=TRUE);
> b<-a[order(as.Date(a$date, format="%m/%d/%Y")),]
> 
> ggplot(data=b) + geom_line(aes(x=date, y=value, group=id, colour=
> factor(id))) + facet_wrap(~id, scales = "free")
> 
> 
> 
> 
> 
> 
> DATA:
> 
> 
> id      date    value
> 001     8/16/10 <0.16
> 001     10/25/10        <0.16
> 001     11/8/10 0.42
> 001     11/22/10        0.81
> 001     12/6/10 <0.16
> 002     8/18/10 2.93
> 002     10/25/10        2.4
> 002     11/8/10 1.36
> 002     11/22/10        1.22
> 004     8/20/10 0.77
> 004     10/25/10        0.85
> 004     11/8/10 1.22
> 004     11/22/10        0.21
> 004     12/6/10 1.81
> 004     10/26/11        0.54
> 005     6/4/09  1.33
> 005     6/18/10 1.32
> 005     8/25/10 2.5
> 005     9/15/10 1.3
> 005     10/25/10        1.1
> 005     11/8/10 0.66
> 005     11/22/10        0.84
> 005     12/6/10 7.42
> 005     11/4/11 1.21
> 006     9/23/10 0.97
> 006     10/25/10        2.25
> 006     11/8/10 0.51
> 006     11/22/10        0.53
> 006     12/6/10 0.41
> 008     8/25/10 3.14
> 008     10/25/10        3.58
> 008     11/8/10 2.41
> 008     12/6/10 2.08
> 008     6/11/12 3.2
> 009     10/6/10 0.24
> 009     11/22/10        0.34
> 009     2/2/11  0.58
> 009     2/16/11 0.54
> 009     3/2/11  0.25
> 009     3/16/11 0.39
> 010     9/14/10 0.28
> 010     2/2/11  0.19
> 010     2/16/11 0.42
> 010     3/2/11  0.39
> 010     3/16/11 0.26
> 011     8/20/10 <0.16
> 011     2/2/11  <0.16
> 011     2/16/11 <0.16
> 011     3/2/11  <0.16
> 011     3/16/11 1.76
> 011     10/26/11        <0.16
> 012     12/14/10        0.48
> 012     2/2/11  1.2
> 012     2/16/11 0.44
> 012     3/2/11  0.32
> 012     3/16/11 0.34
> 013     11/13/09        0.73
> 013     8/19/10 3.32
> 013     2/2/11  13.7
> 014     2/6/13  1.35
> 014     4/24/13 0.85
> 014     8/18/10 0.66
> 014     10/5/10 0.68
> 014     10/27/10        0.53
> 014     2/2/11  0.54
> 014     2/16/11 0.49
> 014     3/2/11  0.31
> 014     3/16/11 0.4
> 014     6/29/11 0.53
> 014     8/15/11 0.55
> 014     8/15/12 0.94
> 014     10/31/12        0.74
> 015     12/10/10        0.4
> 015     2/2/11  0.44
> 015     3/2/11  0.38
> 015     3/16/11 0.43
> 016     12/17/10        0.18
> 016     1/25/11 <0.16
> 016     2/2/11  0.53
> 016     2/2/11  0.54
> 016     2/16/11 0.46
> 016     3/2/11  0.29
> 016     3/16/11 0.2
> 016     3/20/12 0.18
> 016     3/26/12 0.23
> 016     3/30/12 0.52
> 016     4/2/12  0.33
> 016     4/23/12 0.3
> 017     11/17/11        3.35
> 017     12/9/11 2.56
> 018     2/25/13 18.1
> 018     3/11/13 14.9
> 018     3/25/13 11.1
> 018     4/10/13 8.47
> 018     4/22/13 15.9
> 
> 
> ______________________________________________
> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth



More information about the R-help mailing list