[英]Plotting overlaying time series
我要绘制四个时间序列,最好使用基础图形。
year<-c(2000,2001,2002,2003,2004,2005,2006,2007) #x axis
a<-c(36.2,42.4,43.4,56.4,67.4,42.4,22.4,20.4)
b<-c(NA,NA,NA,56.4,67.4,42.4,22.4,20.4)
c<-c(36.4,42.3,43.7,56.4,67.2,88.3,99.3,99.9)
d<-c(36.4,42.3,43.7,56.4,NA,NA,NA,NA)
#using different thickness of lines to distinguish between them? Dunno
par(mar = c(4,4,4,4))
par(mfrow=c(1,2))
plot(year,a, xlab="Year", ylab="Whatever", type="l", lwd=6, ylim=c(20, 100))
lines(year,b, type="l", lwd=2, col="yellow")
plot(year,c, xlab="Year", ylab="Whatever", type="l", lwd=6, ylim=c(20, 100))
lines(year,d, type="l", lwd=2, col="yellow")
如您所见,两个系列中的一个始终是另一个系列的子集,并且系列a和b在开始时就非常相似,因此在一个具有这种特征的图中看起来并不好。 您对如何绘制此类数据有任何建议吗? 我不介意将所有内容都放在一个图中,但这不是必需的。 干杯。
这使用plot.zoo,后者依次使用基本图形并接受大多数基本图形的图形参数。 请注意,在plot.zoo
, col
和lwd
被回收。 screen
参数指示每个系列所处的位置,以便将其全部放入一个面板中,并将screen
参数替换为screen = 1
。 根据需要添加main
和其他参数。 请参见?plot.zoo
和下面的第?plot.zoo
图。
library(zoo)
plot(zoo(cbind(a, b, c, d), year), screen = c(1, 1, 2, 2),
col = c("black", "yellow"), ylim = c(20, 100), lwd = c(6, 2))
还要注意,在这种情况下,只需添加library(lattice)
并将plot
更改为xyplot
我们就可以通过xyplot.zoo
(下面的第二个绘图)获得格子图。
怎么样呢?
year <- c(2000,2001,2002,2003,2004,2005,2006,2007) #x axis
a <- c(36.2,42.4,43.4,56.4,67.4,42.4,22.4,20.4)
b <- c(NA,NA,NA,56.4,67.4,42.4,22.4,20.4)
c <- c(36.4,42.3,43.7,56.4,67.2,88.3,99.3,99.9) - 100
d <- c(36.4,42.3,43.7,56.4,NA,NA,NA,NA) - 100
#using different thickness of lines to distinguish between them? Dunno
par(mar = c(4,4,4,4))
par(mfrow=c(1,1))
plot(year,a, xlab="Year", ylab="Whatever", type="l", lwd=6, ylim=c(-100, 100))
lines(year,b, type="l", lwd=2, col="yellow")
lines(year,c, xlab="Year", ylab="Whatever", type="l", lwd=6, ylim=c(-100, 100))
lines(year,d, type="l", lwd=2, col="yellow")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.