How to set line width to 0.5 pt in ggplot2?

In ggplot2, it is easy to use element_textwith an argument size=6to set the font size to 6 pt (for text, the size has a pt block). However, we cannot use element_linewith an argument size=0.5to set the line width to 0.5 pt (for a line, the size does not have one). So how to solve this problem?

In the package gridI meet a similar question. The code is as follows:

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

and the result: enter image description here

Obviously, the line width is not equal to 2 cm compared to the width or height of the rectangle.

+2
source share
1 answer

the lwd unit is obviously 1/96 of an inch for a pdf device and it runs 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))

enter image description here

Windows :

enter image description here

+1

Source: https://habr.com/ru/post/1689928/


All Articles