使用 ggplot 时,我可以将 shape
设置为 21-25,以获得具有内部 (fill
) 和边框 (col
) 颜色,如下所示:
df <- data.frame(id=runif(12), x=1:12, y=runif(12))
ggplot(df, aes(x=x, y=y)) +
geom_point(aes(fill=id, size=id), colour="black", shape=21)
但是,我不知道如何控制形状边界的厚度,无论是绝对设置还是作为美学映射。我注意到,如果我设置 lwd
值,它会覆盖 size
美学:
ggplot(df, aes(x=x, y=y)) +
geom_point(aes(fill=id, size=id), colour="black", shape=21, lwd=2)
如何控制边框粗细?
最佳答案
从ggplot2版本2.0.0开始,控制点边框厚度有一个参数。来自 NEWS.md
文件:
geom_point() gains a stroke aesthetic which controls the border width of shapes 21-25 (#1133, @SeySayux). size and stroke are additive so a point with size = 5 and stroke = 5 will have a diameter of 10mm. (#1142)
因此,现在正确的解决方案是:
df <- data.frame(id=runif(12), x=1:12, y=runif(12))
ggplot(df, aes(x=x, y=y)) +
geom_point(aes(fill=id, size=id), colour="black", shape=21, stroke = 2)
关于r - ggplot中的控制点边框厚度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506630/