简体   繁体   中英

How can I modify a legend in ggplot2 to suppress a line overlaying a symbol?

I'd like to plot two series as points, and add a smooth for each series. I'd like the legend to display the symbols. The unwanted behavior is drawing lines through the symbols in the legend (as result of the geom_smooth).

How can I get the lines out of the legend?

Here's an example:

library (ggplot2)


df = data.frame (x=1:6, y = c(1,4,3,8,5,12), z = c(1,2,1,2,1,2))
df$z = factor(df$z)

p = ggplot (df, aes(x=x, y=y, shape = z, color=z))
p = p + scale_color_manual (values = c("green", "blue"))
p = p + scale_shape_manual (values = c(16,17))
p = p + geom_point(size = 6)
p
#--legend is perfect
p = p + geom_smooth(aes(color=z))
p
#--symbols in legend have superimposed lines

设置show_guide = FALSE

p + geom_smooth(aes(color=z), show_guide  = FALSE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM