r - ggplot中的控制点边框厚度

标签 r ggplot2 border point thickness

使用 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)

enter image description here

但是,我不知道如何控制形状边界的厚度,无论是绝对设置还是作为美学映射。我注意到,如果我设置 lwd 值,它会覆盖 size 美学:

ggplot(df, aes(x=x, y=y)) + 
  geom_point(aes(fill=id, size=id), colour="black", shape=21, lwd=2)

enter image description here

如何控制边框粗细?

最佳答案

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)

Output

关于r - ggplot中的控制点边框厚度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506630/

相关文章:

r - 使用 rlang,将 `...` 的内容转换为字符向量

r - 绘制大型数据集的堆积条形图并在 r 中设置绘图的条形限制

html - IMG 标签上的奇怪边框

r - 如何让 geom_boxplot 更改时间序列中组的颜色?

r - 直接从包源的 URL 安装 R 包

在 Shiny 的应用程序中关闭它时重置模态

r - geom_bar() + 象形图,怎么做?

r - 为什么 geom_smooth() 自动排除某些值?

css - 如何将顶部边框放在仅覆盖 css 中的字母的标题上

c# - 如何使用 C# 在 excel 中的多个单元格周围设置边框