How is line width (size) determined in ggplot2?

The aesthetics of line width ( size) in ggplot2seems to print about 2.13 pt wider lines in pdf (an experiment was performed in Adobe Illustrator with Mac):

library(ggplot2)

dt <- data.frame(id = rep(letters[1:5], each = 3), x = rep(seq(1:3), 5), y = rep(seq(1:5), each = 3), s = rep(c(0.05, 0.1, 0.5, 1, 72.27/96*0.5), each = 3))

lns <- split(dt, dt$id)

ggplot() + geom_line(data = lns[[1]], aes(x = x, y = y), size = unique(lns[[1]]$s)) + 
  geom_text(data = lns[[1]], y = unique(lns[[1]]$y), x = 3.5, label = paste("Width in ggplot =", unique(lns[[1]]$s))) + 
  geom_line(data = lns[[2]], aes(x = x, y = y), size = unique(lns[[2]]$s)) + 
  geom_text(data = lns[[2]], y = unique(lns[[2]]$y), x = 3.5, label = paste("Width in ggplot =", unique(lns[[2]]$s))) + 
  geom_line(data = lns[[3]], aes(x = x, y = y), size = unique(lns[[3]]$s)) + 
  geom_text(data = lns[[3]], y = unique(lns[[3]]$y), x = 3.5, label = paste("Width in ggplot =", unique(lns[[3]]$s))) + 
  geom_line(data = lns[[4]], aes(x = x, y = y), size = unique(lns[[4]]$s)) + 
  geom_text(data = lns[[4]], y = unique(lns[[4]]$y), x = 3.5, label = paste("Width in ggplot =", unique(lns[[4]]$s))) + 
  geom_line(data = lns[[5]], aes(x = x, y = y), size = unique(lns[[5]]$s)) + 
  geom_text(data = lns[[5]], y = unique(lns[[5]]$y), x = 3.5, label = paste("Width in ggplot =", unique(lns[[5]]$s))) + 
  xlim(1,4) + theme_void()

ggsave("linetest.pdf", width = 8, height = 2)

# Device size does not affect line width:
ggsave("linetest2.pdf", width = 10, height = 6)

enter image description here

I read that you should multiply the line width by 72.27 / 96 to get the line width in pt , but the experiment above gives me a line width of 0.8 pt when I try to get 0.5 pt.

As @Pascal points out , the line width does not seem to match the pt to mm conversion, which works for fonts and was defined by @hadley in one of the comments . That is, the line width, apparently, is not determined by the "magic number" 1 / 0.352777778.

What is the line width equation for ggplot2?

+4
1

. -, ggplot2 size ggplot2::.pt, 72.27/25.4 = 2.845276 ( 165 geom-.r):

> ggplot2::.pt
[1] 2.845276

, , 72.27/96 R . , :

> ggplot2::.pt*72.27/96
[1] 2.141959

, ggplot2 size = 1 2.14pt, 0,8 pt 0,8/2,141959 = 0,3734899 ggplot2.

+1

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


All Articles