简体   繁体   English

如何在 ggplot2 中用 x 轴上的时间间隔和 y 轴上的值绘制折线图?

[英]How to plot a line graph in ggplot2 with With time interval on x axis and values on y axis?

I am trying to plot line graph with ggplot in r having only equally spaced time interval on x axis and values corresponding to time interval on y axis.我试图在 r 中用 ggplot 绘制折线图,​​在 x 轴上只有等距的时间间隔,而在 y 轴上的时间间隔对应的值。

Time     Demand 
00:15  506.88 
00:30  506.88 
00:45  506.88 
1:00   506.88 
1:15   501.12 
1:30   501.12 
1:45   489.6 
2:00   501.12 
2:15   460.8 
2:30   455.04 
2:45   460.8 
3:00   460.8 
3:15   443.52

The issue is your Time column is going to be read in as a factor rather than as a number or a datetime.问题是您的Time列将作为一个因素而不是数字或日期Time被读入。 Quick way to get around this is to set group = 1 .解决这个问题的快速方法是设置group = 1 Assuming your dataframe is called my_data :假设您的数据my_data称为my_data

ggplot(data = my_data,
       aes(x = Time,
           y = Demand,
           group = 1)) + 
   geom_line()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM