我喜欢用一种解决方法是使用相同的期望的美学(Alpha设置为0,从而它不与所得到的曲线图干扰)添加另一个的geom层,从而使填充图例取决于而非geom_label
层。示意图下:
# instead of this
p1 <- ggplot(mtcars,
aes(wt, mpg, fill = factor(cyl),
label = rownames(mtcars))) +
geom_label()
# try this
p2 <- ggplot(mtcars,
aes(wt, mpg, fill = factor(cyl),
label = rownames(mtcars))) +
geom_label(show.legend = FALSE) +
geom_tile(alpha = 0) +
guides(fill = guide_legend(override.aes = list(alpha = 1)))
(您可以使用geom_point
层也一样,如果你喜欢的点状传奇钥匙。形状21-25填写接受作为审美。)