Good Day Everyone
I have issue that ggplot2 is creating two different legends but for the same variables (See attached image).
Does someone have an idea how to merge these two legends into one? That in the end it shows the different linetypes and colors in the same plot. I think is the problem that I am combining lines with points and therefore it has issues merging them together. Because I plotted it once without the blue points and then it worked perfectly fine with the two different linetypes and colors in the same legend.
You can find the code attached. Thank you very much in advance!
ggplot(data = dat, aes(x = Tag)) +
ggtitle("Meteorologische Bedingungen") +
labs(x = "Zeit", caption = "Data Source: MeteoSchweiz", linetype = "Variablen")+
theme_minimal()+
geom_line(aes(y = Temp, color = "Temperatur", linetype="Temperatur"), size = 1)+
geom_point(aes(y=Regen, color = "Regen"))+
geom_line(aes(y=Feucht*b, color = "Luftfeuchtigkeit", linetype = "Luftfeuchtigkeit"), size = 1)+
scale_y_continuous("Temperatur [°C]", sec.axis = sec_axis(~ (. - a)/b, name = "Luftfeuchtigkeit (relativ) [%]")) +
scale_color_manual(name = "Variablen",
breaks = c("Temperatur", "Luftfeuchtigkeit", "Regen"),
values = c("Temperatur" = "#B2182B", "Luftfeuchtigkeit" = "grey44", "Regen"="blue"))+
scale_linetype_manual(breaks = c("Temperatur", "Luftfeuchtigkeit"),
values = c("Temperatur" = "solid", "Luftfeuchtigkeit" = "dashed"))+
theme(
plot.title = element_text(color = "black", size = 15, face = "bold",hjust = 0),
plot.subtitle = element_text(color = "black",size = 12),
plot.caption = element_text(color = "black", face = "italic", hjust= 1.1, vjust = 20))