Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning multiple xts time series plots

Tags:

plot

r

zoo

xts

I have an xts object with 4 columns. The first 3 columns are the mean and lower and upper confidence bounds for a proportion. The 4th column is the sample size. Since the scales are different, I thought it would make sense to plot the first 3 columns on one graph, and plot the 4th on a separate graph, right below it. Any suggestions on how to do this?

Here's code to build an xts object that's like the one I have:

startTime = Sys.time()
n = 10
d = seq(startTime,startTime+n*24*60*60,by="1 day")
a = sample(10000,length(d),replace=TRUE)
p = runif(length(d))
l = p/2
u = p+(p+1)/2
x= xts(p,d)
x = cbind(x,l,u,a)
colnames(x) = c("prop","low","high","size")
like image 634
DavidR Avatar asked Jan 27 '26 01:01

DavidR


1 Answers

It's easy to do if you use plot.zoo. Something like this will get you started:

library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
plot.zoo(x, screens=c(1,1,1,2))

There are tons of examples in ?plot.zoo; make sure to check them out.

like image 60
Joshua Ulrich Avatar answered Jan 28 '26 18:01

Joshua Ulrich