Problems creating datetime series graph in R using ggplot

[亡魂溺海] 提交于 2019-12-07 00:57:25

As suggested you have to format the Date column into a Date object.

data$Date<-as.Date(data$Date, format="%d/%m/%Y")

Now you can use your script in order to create the plot:

library("ggplo2") 
library("scales")
p <- ggplot(data,aes(x = Date, y = Var,group = 1)) 
        + geom_line() 
        + scale_x_date(labels = date_format("%m/%d/%Y")) 
        + scale_y_continuous(limits = c(0, 70000))    
p

And this is the resulting plot:

Thanks for the comments. They helped me to find out the solution. Both comments allow to represent my data. However, there is small problem: data from the same day is grouped and it is not possible to see the daily behaviour of the variable. I tested to format the Date column using the next command:

as.POSIXct(data$Date, format="%d/%m/%Y %H:%M:%S")    

It worked out. However it is important to have the original data in the format d/m/Y h:m:s. Thanks very much for the comments which help me a lot to solve my problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!