[英]Plot multiple time series in different panels using R
I am trying to plot time series monthly mean temperature data of 9 stations (A to I) putting in 9 different panels.我试图在 9 个不同的面板中绘制 9 个站(A 到 I)的时间序列月平均温度数据。 But I am using zoo to keep the month-year format.
但我正在使用动物园来保持月年格式。 My simple data set looks like below.
我的简单数据集如下所示。
+--------+------+------+------+------+ | Time | A | B | C | D | +--------+------+------+------+------+ | Jan-84 | 28.2 | 28.2 | 27.5 | 18.4 | | Feb-84 | 29.5 | 26.6 | 27.9 | 17.4 | | Mar-84 | 30.7 | 30.3 | 30.1 | 19.5 | | Apr-84 | 30.5 | 33.2 | 29.9 | 20.7 | | May-84 | 33.2 | 30.1 | 30.2 | 21 | | Jun-84 | 31.6 | 28.3 | 28.5 | 16.9 | | Jul-84 | 31.5 | 28.6 | 27.7 | 16.8 | | Aug-84 | 32.5 | 28.9 | 27.4 | 18.5 | | Sep-84 | 34 | 28.1 | 29.4 | 18.3 | | Oct-84 | 32.8 | 28.8 | 28.8 | 17.2 | | Nov-84 | 28.9 | 31.6 | 29 | 17.8 | | Dec-84 | 30.6 | 26.9 | 28.1 | 18.9 | | Jan-85 | 31.8 | 28.6 | 29.3 | 18.2 | | Feb-85 | 31.3 | 29.6 | 30.4 | 19.5 | | Mar-85 | 32 | 31.1 | 31.4 | 19.7 | +--------+------+------+------+------+
I think you'll get better results if you make a proper zoo
object. 我认为,如果制作合适的
zoo
物体,将会获得更好的结果。 For example, using your original dat
例如,使用原始
dat
zz <- zoo(dat[-1], as.yearmon(dat$Time,format="%b-%y"))
plot(zz)
With complete dataset you can pass X = dat[2:9]. 使用完整的数据集,您可以传递X = dat [2:9]。 For 9 plots make par(mfrow=c(9,1)).
对于9个图,请设置par(mfrow = c(9,1))。
par(mar=c(1,1,1,1))
par(mfrow=c(4,1))
apply(X = dat[2:5],MARGIN = 2,FUN = plot,x=dat$Time,type="l",col="blue",xlab="Years",ylab="temperature")
library(lubridate)
dat$Time <- as.POSIXct(dmy(paste("01-", dat$Time , sep ="")))
library(foqat)
geom_ts_batch(dat)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.