0

Im new to R, and I am not able to add a legend to my chart in R, ggplot.

The code is:

ggplot(utregnet_data_R, aes(x= Sted)) +  
geom_line(aes(y = Alder.ar,group=1), color = "black") +
geom_line(aes(y = Fremmede.arter.prosent,group=2), color = "red") +
geom_line(aes(y = onskede.arter.prosent,group=3), color = "blue") +
labs(x="Sted", y="Prosent")

I have tried the method answered in: https://community.rstudio.com/t/adding-manual-legend-to-ggplot2/41651

But it will not work.

Does anyone have a solution?

I tried this method https://community.rstudio.com/t/adding-manual-legend-to-ggplot2/41651 but It did not work.

stefan
  • 90,330
  • 6
  • 25
  • 51
  • If you want a legend you have to map on aesthetics, i.e. move `color=...` inside `aes()`. But the preferred approach would be to reshape your data. – stefan Feb 21 '23 at 17:32

0 Answers0