Is there a way to convert or instruct ggplot to interpret a Dates column as a continuous variable?
My data ( df ) is as follows:
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 tried to build 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 a Date to Date object (e.g. col=as.Date(Date) ), I get the following error:
Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
The goal is for the Date column to define the color of the dots, with the earliest dates having color red and later dates having green in the color gradient.
source share