I have a CSV file called gdata.csv, with data like:
id,date,totKm,eLiter,euros,liters,km
1,24-04-2010,23678,1.180,42.00,35.59,450
2,16-05-2010,24058,1.200,43.00,35.83,380
3,27-05-2010,24488,1.160,44.00,37.93,430
4,12-06-2010,24960,1.180,45.00,38.14,472
With ggplot2
I just want to plot date and eliter in a line char with ggplot2, with this code:
x_date <- as.Date(gdata$date, format = "%d-%m-%Y")
ggplot(eliter, aes(x_date, eliter)) + geom_line()
But, it returns this error related with the class: Error: ggplot2 doesn't know how to deal with data of class numeric
I have tried to make a data.frame but it stills returns the error:
d <- data.frame(xdate = x_date, yeliter=gdata$eLiter)
ggplot(d$xdate, aes(d$xdate, d$yeliter)) + geom_line()
Error: ggplot2 doesn't know how to deal with data of class Date
With plot
I have managed to do this with plot() function:
plot(gdata$eLiter~as.Date(gdata$date, "%d-%m-%Y"), type = "s", xlab="Date",ylab="€/Liter", main="€/liter trend", col='blue')
And it works fine! But I can not do it with ggplot.
Could anyone help me?
Thank you very much.

x_dateto your data frame, still pass ggplot the entire data frame, that isggplot(d, aes(...))notggplot(d$xdate, aes(...)). The error message is telling you that you're passing ggplot a single vector of dates where it's expecting a full data frame.$insideaes(). The point of ggplot having adataargument is that you don't keep re-typing the data frame.ggplot(d, aes(x = xdate, y = yeliter)) + geom_line().