Using ggplot2
, I have two vertically aligned geom_line()
objects and I want to draw a vertical rectangle across both plots in the same x_axis
range.
For example, how could this rectangle be extended down across the plot below?
paquetes <- c("ggplot2", "gcookbook", "cowplot")
lapply(paquetes, require, character.only = TRUE)
p <- ggplot(subset(climate, Source=="Berkeley"), aes(x=Year, y=Anomaly10y)) +
geom_line() +
annotate("rect", xmin=1950, xmax=1980, ymin=-1, ymax=1, alpha=.1,
fill="blue") +
theme(axis.line.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank())
w <- ggplot(subset(climate, Source=="NASA"), aes(x=Year, y=Anomaly1y)) +
geom_line()
both <- cowplot::plot_grid(p + theme(legend.position = "none"),
w + theme(legend.position = "none"),
align = "v",
ncol = 1,
nrow = 2)
both