Is there anyway to convert or instruct ggplot to interpret a column of Dates as a continuous variable?
My data (df
) looks like the following:
Location Date Value
56.28,-36.57 2011-01-10 32
56.28,-36.57 2010-02-08 40
52.24,-36.58 2010-03-22 18
52.24,-36.58 2011-06-14 39
52.25,-36.59 2012-04-10 41
52.25,-36.59 2010-04-09 38
I have tried to plot the data with the following command:
g=ggplot(df) + geom_boxplot(aes(factor(Location),Value, col=Date))+ geom_jitter(aes(factor(Location),Value),size=1) + scale_colour_gradient(low='red',high='green')
But received the following error message:
Error: Discrete value supplied to continuous scale
If I convert the Date to a Date object (e.g. col=as.Date(Date)
), I receive the following error:
Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
The goal is to have the Date column dictate the color of the points, with earliest dates having color red and later dates having the color green on the color gradient.