2014-04-19 44 views
0

我有四个时间序列,我想绘制,最好使用基本图形。绘制覆盖时间系列

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的子集,在他们开始非常相似,所以它不会在一个情节好看(这个特性)。 你有任何建议如何绘制这种数据?我不介意在一个情节中拥有这一切,但这不是必要的。 干杯。

回答

3

这使用plot.zoo,它反过来使用基本图形并接受大部分基本图形图形参数。请注意,在plot.zoocollwd被回收。参数screen指示每个系列在哪个位置,以便将其全部置于一个面板中,用screen = 1代替screen参数。根据需要添加main和其他参数。请参阅下面的?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),改变plotxyplot我们可以通过xyplot.zoo得到格图(下图2图)。

plot.zoo plot

xyplot.zoo plot

+0

有什么办法如何把它们彼此相邻?我尝试了'rbind'而不是'cbind',它不起作用。 – Vochmelka

+1

@Vochmeika,'plot.zoo'参数'nc = 2'会将面板绘制成两列而不是一列。 –

0

什么是这样的:

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