1

I'd like to plot correctly the legend in the graphic of the MWE, i.e a line for PSO and a pointed line for Approach.

mean_f2 <- data.frame(Probabilities = seq(0.1, 1, 0.1), Approach = runif(10),
                      PSO =  10*runif(10))

g2 <- ggplot(data = mean_f2, aes(x = Probabilities)) + 
             geom_point(aes(y = Approach, colour = 'Approach')) + 
             geom_line(aes(y = Approach, colour = 'Approach')) +
             geom_line(aes(y = PSO, colour = 'PSO')) + 
             scale_colour_manual('', breaks = c('Approach', 'PSO'), 
                      values = c('Approach' = 'black', 'PSO' = 'gray')) +
            scale_x_continuous(breaks = seq(0.1, 1, 0.1), limits = c(0.1, 1)) +
               xlab('Probabilities') + ylab('Error') + theme_bw()
g2

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
Wagner Jorge
  • 430
  • 3
  • 15
  • Possible duplicate of [Using override.aes() in ggplot2 with layered symbols (R)](https://stackoverflow.com/questions/29307725/using-override-aes-in-ggplot2-with-layered-symbols-r) – erocoar Mar 06 '18 at 13:34

1 Answers1

2

Is this what you want?

enter image description here

Produced with:

g2 + guides(color = guide_legend(override.aes = list(pch = c(16, NA))))
mt1022
  • 16,834
  • 5
  • 48
  • 71