I am trying to plot on a facet_wrap using geom_line two different variables of different sizes (the second one has a lot of NA) but using the same x axis (Years). Unfortunately the lines plots only for the biggest variable. How can I do it?
Here is an example of the format of my data, and my simplified code:
Sector | Scenario | Year | Emissions1 | Emissions2 |
---|---|---|---|---|
Buildings | S1 | 2019 | 65 | NA |
Buildings | S1 | 2020 | 45 | 75 |
Buildings | S2 | 2021 | 25 | NA |
Buildings | S2 | 2022 | 67 | NA |
Transport | S1 | 2019 | 86 | 65 |
Transport | S1 | 2020 | 86 | 59 |
Transport | S2 | 2021 | 68 | NA |
..... | ..... | ..... | ..... | ..... |
Title <- paste("World total GHG emissions, exc. LULUCF, all scenarios")
Subheader <- paste("Subheader ")
(Plot <- FinalTableAverage %>%
filter(Sector == 'Transport') %>%
select(-Sector) %>%
pivot_longer(c(4:last_col()), names_to = 'Model', values_to = 'Value') %>%
ggplot(aes(x = as.numeric(Year), y = Value, color = Model )) +
geom_line(size=1) +
geom_point(size=1.5) +
ggtitle(Title , subtitle = Subheader ) +
theme_bw() +
facet_wrap(~ Scenario, scale = "free")+
theme(axis.title = element_blank(),
plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 10),
legend.position = "bottom",
legend.title = element_blank())
)