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

查看:378
本文介绍了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屋!

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