0

I am trying to add a legend to my graph. How would I do this in the case with multiple lines? Calgary would be red, edmonton blue, ect. Thanks.

library(ggplot2)

Year = c(2018, 2019, 2020, 2021, 2022)
Calgary = c(128, 121, 109, 76, 142)
Edmonton = c(118, 139, 158, 161, 120)
Lethbridge = c(16, 6, 19, 8, 21)
Red_Deer = c(17, 12, 13, 10, 10)
Maskwacis = c(9, 9, 10, 9, 5)
cities <- as.data.frame(cbind(Year,Calgary,Edmonton,Lethbridge,Red_Deer,Maskwacis))
ggplot(cities, aes(Year)) +
  geom_line(aes(y = Calgary),col ="red") +
  geom_line(aes(y = Edmonton),col ="blue")+
  geom_line(aes(y = Lethbridge),col ="yellow")+
  geom_line(aes(y = Red_Deer),col ="green")+
  geom_line(aes(y = Maskwacis),col ="purple")+
  labs(title = "Geographic Distribution", x = "Year", y = "Geographical Area")
Megan D
  • 25
  • 4

0 Answers0