Closed
Description
How to reproduce:
library(data.table)
library(lubridate)
library(ggplot2)
# Prepare some random data
set.seed(1234)
dt <- data.table(x = rnorm(365*5), d = seq(ymd(20130101), ymd(20131231), by = 86400))
dt.m <- dt[, list(total = sum(x)), by = list(month = floor_date(d, "month"))]
# Create a basic scatterplot chart
p <- qplot(month, total, data = dt.m)
This works:
# Both of these work as expected and produce the same result
p + geom_segment(x = as.numeric(ymd(20130401)), xend = as.numeric(ymd(20130701)),
y = -10, yend = 10)
p + geom_segment(aes(x = ymd(20130401), xend = ymd(20130701),
y = -10, yend = 10))
but this doesn't:
> p + annotate("segment", x = as.numeric(ymd(20130401)), xend = as.numeric(ymd(20130701)),
y = -10, yend = 10)
Error: Invalid input: time_trans works with objects of class POSIXct only
> p + annotate("segment", x = ymd(20130401), xend = ymd(20130701),
y = -10, yend = 10)
Error in Ops.POSIXt((x - from[1]), diff(from)) :
'/' not defined for "POSIXt" objects
> p + annotate("segment", aes(x = ymd(20130401), xend = ymd(20130701),
y = -10, yend = 10))
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ""uneval"" to a data.frame
I have also posted a question to SO - there may be some additional details there. http://stackoverflow.com/questions/18796386/how-to-use-ggplot2s-annotate-with-dates-in-x-axis
Metadata
Metadata
Assignees
Labels
No labels