Gantt Chart, geom_vline inserting Today's Date as 1970

92 views
Skip to first unread message

Brandon Hurr

unread,
Dec 6, 2012, 11:52:38 AM12/6/12
to ggplot2
When I run this code, I get the chart that I want, but for some reason it puts the vline as 1970 instead of today's date. Anyone got any idea why? 

Tried two machines with different versions. 

Brandon

require(ggplot2)

require(lubridate)

tasks<-structure(list(SMC.PI = c(8893L, 8893L, 8893L, 8893L, 8893L, 8893L, 8893L, 8893L, 8893L, 8893L), SubProject = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Ripening Physiology", class = "factor"),     SubSubProject = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,     1L, 1L), .Label = "Fruit Color", class = "factor"), Workstream.ID = structure(c(1L,     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("1.2.1.04",     "1.2.1.06"), class = "factor"), Workstream.Name = structure(c(1L,     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("Pepper",     "Tomato"), class = "factor"), Process = structure(c(8L, 3L,     5L, 6L, 1L, 7L, 4L, 5L, 2L, 8L), .Label = c("Analytical",     "Candidate Gene", "Cultivation", "Data Analysis", "QTL Analysis",     "Sampling", "Sequencing", "Total"), class = "factor"), Owner = structure(c(4L,     6L, 3L, 2L, 5L, 1L, 4L, 3L, 4L, 4L), .Label = c("?", "BA",     "GPL", "Hurr", "Kende", "Nicolet"), class = "factor"), Location = structure(c(2L,     3L, 1L, 3L, 2L, 4L, 2L, 1L, 2L, 2L), .Label = c("FRSS", "GBJH",     "MAAG", "USRE"), class = "factor"), Cost = c(NA, NA, NA,     NA, NA, NA, NA, NA, NA, NA), DurationMonths = c(36L, 9L,     1L, 1L, 3L, 2L, 1L, 1L, 1L, 36L), Start = structure(c(1293840000,     1351728000, 1359676800, 1367366400, 1370044800, 1370044800,     1377993600, 1380585600, 1383264000, 1317427200), tzone = "UTC", class = c("POSIXct",     "POSIXt")), End = structure(c(1388534400, 1375315200, 1362096000,     1370044800, 1377993600, 1375315200, 1380585600, 1383264000,     1385856000, 1412121600), tzone = "UTC", class = c("POSIXct",     "POSIXt")), ymin = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,     1L)), .Names = c("SMC.PI", "SubProject", "SubSubProject", "Workstream.ID", "Workstream.Name", "Process", "Owner", "Location", "Cost", "DurationMonths", "Start", "End", "ymin"), row.names = c(NA, -10L), class = "data.frame")

today<-parse_date_time(Sys.Date(), orders="Y-m-d")

ggplot(tasks, aes(xmin = Start
, xmax = End
, ymin = ymin
, ymax = ymin+ 1
, fill = Process
)
) +
geom_rect() +
facet_grid(Workstream.ID+Workstream.Name+SubSubProject+SubProject+SMC.PI~.) +
geom_vline(aes(x=today))+
theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
labs(x="Year")

Inline image 1

#############################
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lubridate_1.2.0 ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.15.1        gtable_0.1.1       labeling_0.1       MASS_7.3-21       
 [8] memoise_0.1        munsell_0.4        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.1     scales_0.2.2      
[15] stringr_0.6.1  

#############################
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lubridate_1.2.0 ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.15.2       
 [5] gtable_0.1.1       labeling_0.1       MASS_7.3-22        memoise_0.1       
 [9] munsell_0.3        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     scales_0.2.2       stringr_0.6.1      tools_2.15.2  
image.png

Chris Neff

unread,
Dec 6, 2012, 11:57:12 AM12/6/12
to Brandon Hurr, ggplot2
The aes for geom_vline is xintercept, not x


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

image.png

Brandon Hurr

unread,
Dec 6, 2012, 12:15:01 PM12/6/12
to Chris Neff, ggplot2
/facepalm

I should know better. But that brings up another confusing error. I'm not sure why it's doing this, because it will take a single value. Unless it's something else? Wasn't there an issue with scale_date reported recently? 


ggplot() +
geom_rect(data=tasks, aes(xmin = Start , xmax = End , ymin = ymin , ymax = ymin + 1, fill = Process)) +
geom_vline(aes(xintercept=today))
Error: Discrete value supplied to continuous scale
image.png

Brandon Hurr

unread,
Dec 6, 2012, 12:16:54 PM12/6/12
to Chris Neff, ggplot2
Yeah. Looking at the examples here I see no reason for the error http://wiki.stdout.org/rcookbook/Graphs/Lines%20(ggplot2)/
image.png

Winston Chang

unread,
Dec 6, 2012, 12:31:57 PM12/6/12
to Brandon Hurr, Chris Neff, ggplot2
You need to use xintercept, and convert it to numeric:

ggplot(tasks, aes(xmin = Start, xmax = End, ymin = ymin, ymax = ymin+ 1, fill = Process)) +
geom_rect() +
facet_grid(Workstream.ID+Workstream.Name+SubSubProject+SubProject+SMC.PI~.) +
geom_vline(aes(xintercept=as.numeric(today)))+
theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
labs(x="Year")

The conversion to numeric is probably a bug. Could you file it on github?
Thanks!
-Winston
image.png

Brandon Hurr

unread,
Dec 6, 2012, 12:56:56 PM12/6/12
to Winston Chang, Chris Neff, ggplot2
Thanks Winston and Chris. 

I'll try and file a bug now. 

Brandon Hurr

unread,
Dec 6, 2012, 1:05:53 PM12/6/12
to Winston Chang, Chris Neff, ggplot2
Reply all
Reply to author
Forward
0 new messages