r - Discrete value/continuous scale error in ggplot2 even when I use a numeric -


i'm trying plot cumulative sum line plot in this stack overflow answer. here data:

example = structure(list(date = structure(c(16594, 16611, 16612, 16616,  16686, 16702, 16723, 16772, 16825, 16827), class = "date"), endorse = c(13,  1, 1, 3, 2, 1, 2, 5, 1, 1)), .names = c("date", "endorse"), row.names = c(8l,  10l, 12l, 14l, 26l, 34l, 40l, 53l, 68l, 69l), class = "data.frame") 

and here ggplot2 command trying execute:

ggplot(data = example, aes(x = date, y = cumsum(endorse))) + geom_line() +    geom_point() + theme(axis.text.x = element_text(angle=90, hjust = 1)) +    scale_x_discrete(labels = example$date) + scale_y_continuous(limits=c(0,30)) + xlab("date") 

i "error: discrete value supplied continuous scale" error. endorse variable (supposed y variable) numeric, i'm not sure what's problem. date discrete.

one suggestion use scale_x_date instead of scale_x_discrete. example:

ggplot(data = example, aes(x = date, y = cumsum(endorse))) +    geom_line() +    geom_point() +    theme(axis.text.x = element_text(angle=90, hjust = 1)) +    scale_x_date() +   scale_y_discrete(limits=c(0,30)) +   xlab("date") 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -