How to set the line width to 0.5 pt in ggplot2?

百般思念 提交于 2019-12-24 00:27:38

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/35135632/how-to-set-the-line-width-to-0-5-pt-in-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!