The following plot is fine but the problem starts after annotation.
pkgs <- c("ggplot2", "dplyr", "lubridate")
for (pkg in pkgs) suppressPackageStartupMessages(require(pkg, character.only = TRUE))
require(ggplot2)
require(dplyr)
require(lubridate)
data("economics", package = "ggplot2")
economics %>%
mutate(year = year(date),
decade = cut_interval(year, length = 10, dig.lab = 6)) %>%
ggplot(aes(date, unemploy/pop)) +
facet_grid(cols = vars(decade), scales = 'free') +
scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
geom_line()
Created on 2021-02-06 by the reprex package (v0.3.0)
After annotation,
pkgs <- c("ggplot2", "dplyr", "lubridate")
for (pkg in pkgs) suppressPackageStartupMessages(require(pkg, character.only = TRUE))
require(ggplot2)
require(dplyr)
require(lubridate)
data("economics", package = "ggplot2")
economics %>%
mutate(year = year(date),
decade = cut_interval(year, length = 10, dig.lab = 6)) %>%
ggplot(aes(date, unemploy/pop)) +
facet_grid(cols = vars(decade), scales = 'free') +
scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
geom_line() +
annotate(geom = "segment", color = "maroon", linetype = "dashed",
x = as.Date("1982-12-01"), xend = as.Date("1982-12-01"),
y = 0, yend = Inf)
Created on 2021-02-06 by the reprex package (v0.3.0)
The free scales are completely destroyed. Is there any way out with this problem?