如何在ggplot2中将线宽设置为0.5 pt?

问题描述 投票:2回答:1

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

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

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

结果是:enter image description here

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

r ggplot2 width line r-grid
1个回答
1
投票

对于pdf设备,lwd单位显然是1/96英寸,并且它在线的两侧对称地延伸

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

enter image description here

但是,在Windows系统中,结果是:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.