Ggplot geom_line does not work today

I have several datasets similar to https://www.dropbox.com/s/j9ihawgfqwxmkgc/pred.csv?dl=0

Downloading them from CSV and then the graphics work fine

predictions$date <- as.Date(predictions$date) plot(predictions$date, predictions$pct50) 

But when I want to use GGPLOT to draw this data, the predicted points, into a graph to compare them with the source points like:

 p = ggplot(theRealPastDataValues,aes(x=date,y=cumsum(amount)))+geom_line() 

This team

 p + geom_line(predictions, aes(x=as.numeric(date), y=pct50)) 

generates the following error:

 ggplot2 doesn't know how to deal with data of class uneval 

But since the first plot(predictions$date, predictions$pct50) works with data, I donโ€™t understand what is wrong.

Edit

 dput(predictions[1:10, c("date", "pct50")]) structure(list(date = c("2009-07-01", "2009-07-02", "2009-07-03", "2009-07-04", "2009-07-05", "2009-07-06", "2009-07-07", "2009-07-08", "2009-07-09", "2009-07-10"), pct50 = c(4276, 4076, 4699.93, 4699.93, 4699.93, 4699.93, 4664.76, 4627.37, 4627.37, 4627.37)), .Names = c("date", "pct50"), row.names = c(NA, 10L), class = "data.frame") 

Edit 2

I change this

 p + geom_line(data = predictions, aes(x=as.numeric(date), y=pct50)) 

and the error changed to:

 Invalid input: date_trans works with objects of class Date only Zusรคtzlich: Warning message: In eval(expr, envir, enclos) : NAs created 

so I think that a hint on How to deal with the "data of the uneval class" error from ggplot2? (see comments) was a good idea, bit still the plot is not working.

+1
r ggplot2 line
source share
1 answer

Your first problem (Edit 2) is that ?geom_line uses mapping=NULL as the first argument, so you need to explicitly specify the first argument data

 p + geom_line(data = predictions, aes(x=as.numeric(date), y=pct50)) 

similar question

The second problem is that your predictions$date is a character vector, and when using as.numeric, it introduces NA s. If you need numbers, you need to first format them as a date, and then convert to numeric

 as.numeric(as.Date(predictions$date), format="%Y%m%d") 
+3
source share

All Articles