Is there a “automatic” way of adding a second x axis bellow the first one?
My data is similar to this:
A1=data.frame(dates=seq(as.Date("2000/1/1"), by="day", length.out=1080),obs=runif(1080,min=-10,max=15))
A2=data.frame(dates=seq(as.Date("2010/1/1"), by="day", length.out=1080),obs=runif(1080,min=-8,max=50))
par(new=T)
plot(A1,ylim=range(min(A1[,2],A2[,2]):max(A1[,2],A2[,2])))
par(new=F)
plot(A2,ylim=range(min(A1[,2],A2[,2]):max(A1[,2],A2[,2])))
The only solution I found was to make it by manually. I have multiple time series with the same length and I would like to overlay the observations and keep the x axis like this:
_________________________________________________
| | | | | |
2000 2001 2002 2003 2004 2005
2010 2011 2012 2013 2014 2015
2020 2021 2022 2023 2024 2025
(...)
each time series with a different colour.
Automatically? Not that I know of.
But I do know that you can (with some effort) do this by hand. For example:
I’ve increased the number of lines in the bottom margin to 10 by setting
mar, to demonstrate how you’d ensure there’s enough room for each row of axis labels.Then you plot, omitting the axes, add the x axis with just the ticks, and then draw each row of text labels using
mtext.If you didn’t need each row to be a different color, you could do this with one call to
axiswhere thelabelsargument consists of a vector likec("2000\n2010\n2020","2001\n2011\n2021","2002\n2012\n2022")and then fiddling withpadjto get them centered correctly.