0

I am trying to get a legend for the following ggplot graph but it somehow doesn't work... Any idea how to fix it ? thank you very much!

Returns_ALL %>% 
  ggplot(aes(x=Date)) + 
  geom_line(aes(y = SMI), linetype = "solid") + 
  geom_line(aes(y = PANELB), linetype = "dashed") +
  geom_line(aes(y = PANELA), linetype = "longdash") +
  scale_x_date(date_breaks="1 month", date_labels = "%b") +
  theme_light() + 
  theme(plot.title=element_text(size=10,hjust = 0.5),axis.text.x=element_text(size=7), 
        axis.text.y=element_text(size=7),) + 
  labs(x="",y="") + 
  geom_vline(xintercept = as.Date(c("2020-03-23","2020-02-19")), linetype = "dotted") + 
  ggsave("Indexes plot.png")
  • To get a legend, you need to define `linetype` inside `aes()`. And to do that you need to change your data from wide to long. If you need more help, please [edit] your question, copy the output of the `dput(head(Returns_ALL))` command from R and paste it into your question (preferred). Alternatively paste the tab delimited data from a spreadsheet program. Please see [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more information. – Ian Campbell Jun 14 '21 at 12:59

0 Answers0