问题
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