Date requires conversion to numeric for geom_vline #735

Closed
bhive01 opened this Issue Dec 6, 2012 · 1 comment

Comments

Projects
None yet
2 participants

bhive01 commented Dec 6, 2012

Sorry for being non-minimal, but at least it's reproducible.

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(xintercept=today))+
theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
labs(x="Year")

####Error: Discrete value supplied to continuous scale

Change to as.numeric and everything is fine.

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")
Owner

hadley commented Feb 24, 2014

This sounds like a great feature, but unfortunately we don't currently have the development bandwidth to support it. If you'd like to submit a pull request that implements this feature, please follow the instructions in the development vignette.

hadley closed this Feb 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment