Skip to content
Prev 323577 / 398503 Next

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

Thank you very much for your help and time.

That works very nicely....Thanks again!



----- 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: Wednesday, May 15, 2013 9:36 AM
Subject: Re: [R] Help me please: gplot, facets_wrap and ordering of x axis
  dates

My appologies, I was in a rush yesterday and a) completely misread the post? and b) did not scroll down far enough.? David W is correct that you need to do something with the data set. <.6 is not a number. 

Also, as David says,? it? sounds like your coversion using as.Date did not work out.? The difficulty from here is that if is graphs then it sounds like your actual data.frame is not exactly the same as what I get if I try to read in the data you included. hat is why supplying the data using something like dput() is important.

I don't see how got something to plot.? However if I get rid of the < in the text file and read in the data , etc I get something that may look like what you want.? See code below.? I renamed the data.frame to dat1, just because it was handy and renamed the variable date to date1 since date is a reserved word in R . Type date() to see what I mean.

Again my applogies for completely misreading the problem
John Kane
Kingston ON Canada
#####################################################
library(lubridate)
library(ggplot2)
? 
dat1? <-?  structure(list(id = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 18L, 18L, 18L, 
18L, 18L), date1 = c("8/16/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/18/10", "10/25/10", "11/8/10", "11/22/10", "8/20/10", 
"10/25/10", "11/8/10", "11/22/10", "12/6/10", "10/26/11", "6/4/09", 
"6/18/10", "8/25/10", "9/15/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "11/4/11", "9/23/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/25/10", "10/25/10", "11/8/10", "12/6/10", "6/11/12", 
"10/6/10", "11/22/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", 
"9/14/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", "8/20/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "10/26/11", "12/14/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "11/13/09", "8/19/10", 
"2/2/11", "2/6/13", "4/24/13", "8/18/10", "10/5/10", "10/27/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "6/29/11", "8/15/11", 
"8/15/12", "10/31/12", "12/10/10", "2/2/11", "3/2/11", "3/16/11", 
"12/17/10", "1/25/11", "2/2/11", "2/2/11", "2/16/11", "3/2/11", 
"3/16/11", "3/20/12", "3/26/12", "3/30/12", "4/2/12", "4/23/12", 
"11/17/11", "12/9/11", "2/25/13", "3/11/13", "3/25/13", "4/10/13", 
"4/22/13"), value = c(0.16, 0.16, 0.42, 0.81, 0.16, 2.93, 2.4, 
1.36, 1.22, 0.77, 0.85, 1.22, 0.21, 1.81, 0.54, 1.33, 1.32, 2.5, 
1.3, 1.1, 0.66, 0.84, 7.42, 1.21, 0.97, 2.25, 0.51, 0.53, 0.41, 
3.14, 3.58, 2.41, 2.08, 3.2, 0.24, 0.34, 0.58, 0.54, 0.25, 0.39, 
0.28, 0.19, 0.42, 0.39, 0.26, 0.16, 0.16, 0.16, 0.16, 1.76, 0.16, 
0.48, 1.2, 0.44, 0.32, 0.34, 0.73, 3.32, 13.7, 1.35, 0.85, 0.66, 
0.68, 0.53, 0.54, 0.49, 0.31, 0.4, 0.53, 0.55, 0.94, 0.74, 0.4, 
0.44, 0.38, 0.43, 0.18, 0.16, 0.53, 0.54, 0.46, 0.29, 0.2, 0.18, 
0.23, 0.52, 0.33, 0.3, 3.35, 2.56, 18.1, 14.9, 11.1, 8.47, 15.9
)), .Names = c("id", "date1", "value"), class = "data.frame", row.names = c(NA, 
-95L))
? 
str(dat1)
dat1$date1? <-? mdy(dat1$date1) # using lubridate 
str(dat1) #? POSIXct object not date object as in your original code

ggplot(data=dat1) + geom_line(aes(x=date1, y=value, group=id, colour=
factor(id))) + facet_wrap(~id, scales = "free")
#####################################################
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails