date scale with boxplot #733

Closed
az0 opened this Issue Dec 5, 2012 · 1 comment

Projects

None yet

2 participants

az0 commented Dec 5, 2012
# Fake data
mydf <-data.frame(
    date=rep(as.Date(sprintf("%04d-%02d-%02d", 2012, 1:12,1)), 10),
    value=rnorm(120))

# There should be 12 boxplots, but there is only one.
ggplot(mydf, aes(date, value)) + geom_boxplot()

# This plots, but x isn't a date scale.
ggplot(mydf, aes(factor(date), value)) + geom_boxplot()

# Error: Invalid input: date_trans works with objects of class Date only
ggplot(mydf, aes(factor(date), value)) + geom_boxplot() + scale_x_date()
Collaborator
wch commented Dec 5, 2012

Because the x variable is continuous, you need to specify grouping:

mydf <-data.frame(
    date=rep(as.Date(sprintf("%04d-%02d-%02d", 2012, 1:12,1)), 10),
    value=rnorm(120))

ggplot(mydf, aes(date, value, group=date)) + geom_boxplot()
@wch wch closed this Mar 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment