ggplot中的控制点边框厚度 [英] Control point border thickness in ggplot

查看:29
本文介绍了ggplot中的控制点边框厚度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ggplot 时,我可以将 shape 设置为 21-25 以获得具有独立设置的内部(fill)和边框(col) 颜色,如下所示:

When using ggplot, I can set shape to 21-25 to get shapes that have independent setting for the internal (fill) and border (col) colors, like so:

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 美学:

However, I can't figure out how to control the thickness of the shape borders, either setting them absolutely or as an aesthetic mapping. I note that if I set an lwd value, it overrides the size aesthetic:

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 文件:

Starting in version 2.0.0 of ggplot2, there is an argument to control point border thickness. From the NEWS.md file:

geom_point() 获得了控制形状 21-25 的边框宽度的笔触美学(#1133,@SeySayux).size 和stroke 是相加的,因此size = 5 和stroke = 5 的点的直径为10mm.(#1142)

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)

因此,现在正确的解决方案是:

Thus, the correct solution to this is now:

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)

这篇关于ggplot中的控制点边框厚度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆