用 R 绘制时间序列 [英] Plotting time series with R
本文介绍了用 R 绘制时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 R 并且我必须绘制 50 点.我的输入数据是这样的:
I'm using R and I've to plot 50 point. My input data are something like these:
Day Pressure
20/01/2013 13:30:00 980
20/01/2013 20:30:00 978
21/01/2013 13:30:00 985
21/01/2013 20:30:00 991
我遇到了一些问题,因为我找不到正确的命令来绘制日与压力的关系图.
I've some problems because I can't find the right command to plot the Day vs the Pressure.
推荐答案
这可能会帮助您使用 ggplot2 绘制数据.
This might help you plot the data using ggplot2.
我使用的数据如下:
Day Pressure
20/01/2013 13:30:00 980
20/01/2013 20:30:00 978
21/01/2013 13:30:00 985
21/01/2013 20:30:00 991
代码如下:
library(ggplot2)
data2 <- read.csv("Stack Overflow/timeseries.csv")
data2
data2$Day <- strptime(data2$Day, format="%d/%m/%Y %H:%M:%S")
ggplot(data2, aes(x=Day, y=Pressure))+geom_point()+xlab("Date")
希望有帮助.
输出
如果您想使用基本图,请使用以下内容:
If you want to use base plot then use the following:
plot(data2$Day,data2$Pressure, xlab="Date",ylab="Pressure")
这篇关于用 R 绘制时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文