I have multiple time series data plots and I need an horizontal line in each plot but with different horizontal values (es. 1st plot: h=50
, 2nd plot: h=48
...).
I tried abline(h=50...
and I get the horizontal line in each plot.
I tried abline(h=c(50,48...
and I get multilple horizontal lines in each plot.
I can't figure out how to get the plot.zoo index in order to plot h=50
in the 1st plot, h=48
in the 2nd plot and so on.
library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
# plot with single line
my.panel <- function(x, ...) {
lines(x, ...)
abline(h=50, col = "red", lty="solid", lwd=1.5 )
}
plot.zoo(x, main="title",
plot.type="multiple", type="o", lwd=1.5, col="blue",
panel=my.panel)
# plot multiple lines in all plots
my.panel <- function(x, ...) {
lines(x, ...)
abline(h=c(50,50,48,50), col = "red", lty="solid", lwd=1.5 )}
plot.zoo(x, main="title",
plot.type="multiple", type="o", lwd=1.5, col="blue",
panel=my.panel)