Question

I have four time series which I want to plot, preferably using base graphics.

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

As you can see, one out of two series is always a subset of the other one and the series a and b are quite similar in their beginning so it would not look good in one plot (of this characteristics). Do you have any suggestion how to plot this kind of data? I wouldn't mind having it all in one plot, but it is not necessary. Cheers.

Was it helpful?

Solution

This uses plot.zoo which in turn uses base graphics and accepts most of the base graphics graphical parameters. Note that in plot.zoo that col and lwd are recycled. The screen argument indicates which each series is in so to put it all in one panel replace the screen argument with screen = 1. Add main and other arguments as desired. See ?plot.zoo and first plot below.

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

Also note that in this case by adding just library(lattice) and changing plot to xyplot we can get a lattice plot via xyplot.zoo (second plot below).

plot.zoo plot

xyplot.zoo plot

OTHER TIPS

What about something like:

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")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top