我想要改变geom_col图例的形状。默认情况下,图例是正方形的,我想改成圆形(或三角形或其他任何形状)。由于颜色由fill
控制,我认为覆盖此参数应该可以解决问题:
library(ggplot2)
data("Titanic")
Titanic <- as.data.frame(Titanic)
ggplot(data = Titanic, aes(x = Class, y = Freq, fill = Survived)) + geom_col() +
guides(fill = guide_legend(override.aes = list(shape = 16)))
我也尝试更具体地说明
ggplot(data = Titanic, aes(x = Class, y = Freq, fill = Survived)) + geom_col() +
scale_shape_manual(values = c("No" = 16, "Yes" = 17))
但是传说没有改变。有什么建议吗?
(我查看了相关问题Changing shape in legend ggplot2,但似乎也不起作用。我想这是因为没有使用
geom_point
?)