0

I have a problem with adding a legend to my plot. My code below:

ggplot(data = dane2, aes(x = iterations, y = powers, color = 'Moc testu')) +
  geom_line(col = 'red')+
  geom_line(data = dane3, aes(x = iterations, y = blad_II_r, color = 'Błąd II rodzaju')
            , color = 'orange')+
  ggtitle('Błąd II rodzaju i moc testu w zależności od ilości iteracji') +
  xlab('iteracja') +
  ylab('') +
  ylim(-0.01, 1) +
  scale_color_manual(name = "", values = c("Moc testu" = "red", "Błąd II rodzaju" = "orange"))+
  guides(color = guide_legend(title = "Legenda")) +
  theme(legend.position = 'right')

The legend doesn't show and I don't know why. Could you help?

I tried to plot with this code and it still doesn't work.

Thanks in advance!

  • What happens if you remove `name = ""` from `scale_color_manual()`? Would be helpful if you can provide the data you're using: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Harrison Jones Jan 24 '23 at 14:48
  • Remove `col = 'red'` from the first geom_line and `color = 'orange'` from the second. – stefan Jan 24 '23 at 14:49
  • 2
    Thank you very much. It works without that arguments. – Kacper Kaszuba Jan 24 '23 at 14:54

0 Answers0