简体   繁体   English

用R绘制时间序列

[英]Plotting time series with R

I'm using R and I've to plot 50 point. 我正在使用R而我要绘制50点。 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. 我遇到了一些问题,因为我无法找到正确的命令来绘制Day vs. the Pressure。

This might help you plot the data using ggplot2. 这可能有助于您使用ggplot2绘制数据。

The data I used was as follows: 我使用的数据如下:

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

The code is as follows: 代码如下:

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")

Hope it helps. 希望能帮助到你。

Output 产量 在此输入图像描述

If you want to use base plot then use the following: 如果要使用基础图,请使用以下内容:

plot(data2$Day,data2$Pressure, xlab="Date",ylab="Pressure")

Using the zoo package read the data into z and plot it: 使用zoo包将数据读入z并绘制它:

Lines <- "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(zoo)
z <- read.zoo(text = Lines, skip = 1, index = 1:2, tz = "", format = "%d/%m/%Y %H:%M:%S")
plot(z)

在此输入图像描述

You need to convert your "Day" column into Date format for that you need to use as.Date("column") conversion trick. 您需要将“日”列转换为日期格式,以便您需要使用as.Date(“column”)转换技巧。 I took the same data as yours 我拿了与你相同的数据

and plotted it. 并绘制它。 http://imgur.com/oyYomZf here..(as i don't have enough reputation points). http://imgur.com/oyYomZf这里..(因为我没有足够的声望点)。

library(ggplot2)
library(scales)

date_count<-read.csv("sample_date.csv")
timeline<-as.Date(date_count$Day)
df<-data.frame(timeline,date_count$Pressure)
date_count.tmp<-ggplot(df, aes(x=timeline, y=date_count$Pressure)) + geom_line() 


summary(date_count.tmp)
save(date_count,file="temp_tags_count.rData")
ggsave(file="sample_datecount.pdf")
ggsave(file="sample_datecount.jpeg",dpi=72)

and there you go with your problem solution. 在那里你可以使用你的问题解决方案。

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

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