I want to use the face_wrap
functionality of ggplot
to draw the following example data. The plot
doesn't seem right. The line
should have smooth connection with no extra space in both facets
(ie Facet A
has empty space from 10-15 while Facet B
has space 0-5). Also the months on the x-axis is a bit odd.
library(tidyverse)
library(lubridate)
set.seed(555)
D <- data.frame(Date = seq(as.Date("2001-01-01"), to= as.Date("2003-12-31"), by="day"),
A = runif(1095, 0,10), Z = runif(1095, 5,15))
D %>% pivot_longer(-Date, names_to = "Variable", values_to = "Value") %>%
mutate(Year = year(Date), Month = month(Date)) %>%
ggplot(aes(x = Month, y = Value, col = as.factor(Year)))+
geom_line()+facet_wrap(~Variable, nrow = 2)
Desired Output: I am looking for a plot like below where the lines have smooth month to month connection.