ggplot中的控制点边界厚度 [英] Control point border thickness in ggplot
问题描述
当使用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),color =black,shape = 21)
但是,我无法弄清楚如何控制形状边框的厚度,或者将它们设置为绝对或者作为审美贴图。我注意到,如果我设置了 lwd
值,它会覆盖大小
审美观:
ggplot(df,aes(x = x,y = y))+
geom_point(aes(fill = id,size = id) =black,shape = 21,lwd = 2)
如何控制边框厚度?
从 ggplot2 的2.0.0版本开始,控制点边框厚度有一个参数。从 NEWS.md
文件中:
$ b
geom_point()控制形状21-25的边框宽度(#1133,@SeySayux)。大小和行程是相加的,所以大小= 5和行程= 5的点将具有10mm的直径。 (#1142)
因此,现在正确的解决方案是:
< pre $ 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),color =black,shape = 21,stroke = 2)
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)
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)
How do I control the border thickness?
Starting in version 2.0.0 of ggplot2, there is an argument to control point border thickness. From the NEWS.md
file:
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屋!