如何在ggplot2中将线宽设置为0.5 pt? [英] How to set the line width to 0.5 pt in ggplot2?

查看:1771
本文介绍了如何在ggplot2中将线宽设置为0.5 pt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ggplot2中,使用 element_text 和参数 size = 6 可以很容易地将字体大小设置为6 pt(对于文本,大小的单位是pt)。但是,我们不能使用带参数 size = 0.5 element_line 来设置线宽为0.5 pt(对于line,size没有单位)。那么如何解决这个问题呢?



grid 包中,我遇到了类似的问题。代码如下:

  library(grid)
grid.rect(width = unit(5,cm ),height = unit(5,cm),gp = gpar(lwd = unit(2,cm)))

,结果是:



显然,线宽与长方形的宽度或高度相比,不是2厘米。

解决方案

一个lwd单位显然是1/96英寸对于pdf设备,它在行的两边对称扩展

  grid.newpage()
网格。 rect(width = unit(1,cm)+ unit(1,mm),
height = unit(1,cm)+ unit(1,mm),
gp = gpar(lwd = 96 / 2.54,alpha = 0.5,linejoin =miter,linejoin = 1))

然而,在Windows系统中,结果是:




In ggplot2, it is easy to use element_text with argument size=6 to set the font size to 6 pt (For text, size has a unit of pt). However, we cannot use element_line with argument size=0.5 to set the line width to 0.5 pt (For line, size has no unit). So how to solve this problem?

In grid package, I meet with the similar question. The code is as following:

library(grid)
grid.rect(width=unit(5, "cm"), height=unit(5, "cm"), gp=gpar(lwd=unit(2, "cm")))

and the result is:

Obviously, the line width is not 2 cm comparing with the width or height of the rectangle.

解决方案

a lwd unit is obviously 1/96 of an inch for the pdf device, and it extends symmetrically on either side of the line

grid.newpage()
grid.rect(width=unit(1, "cm")+unit(1,"mm"), 
          height=unit(1, "cm")+unit(1,"mm"), 
          gp=gpar(lwd=96/2.54, alpha=0.5, linejoin="mitre",linejoin=1))

However, in windows system, the result is:

这篇关于如何在ggplot2中将线宽设置为0.5 pt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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