ggplot2中的正确图例

问题描述 投票:1回答:1

我想在MWE的图形中正确绘制图例,即PSO的一条线和方法的一条尖线。

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

r ggplot2
1个回答
2
投票

这是你想要的吗?

enter image description here

制作:

g2 + guides(color = guide_legend(override.aes = list(pch = c(16, NA))))
© www.soinside.com 2019 - 2024. All rights reserved.