gpt4 book ai didi

r - ggplot2中的线宽(大小)是如何定义的?

转载 作者:行者123 更新时间:2023-12-03 13:32:03 25 4
gpt4 key购买 nike

size 中的线宽 ( ggplot2 ) 美学似乎将大约 2.13 pt 宽的线条打印为 pdf(该实验是在带有 Mac 的 Adob​​e Illustrator 中完成的):

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

我读到了 one should multiply the line width by 72.27/96 to get a line width in pt ,但是当我尝试获得 0.5 pt 时,上面的实验给了我 0.8 pt 的线宽。

As @Pascal points out , line width does not seem to follow the pt to mm conversion that works for fonts and was defined by @hadley in one of the comments . IE。线宽似乎不是由“魔数(Magic Number)”1/0.352777778 定义的。

ggplot2 线宽背后的方程式是什么?

最佳答案

你的帖子里已经有了所有的部分。首先,ggplot2 乘以 size设置者 ggplot2::.pt ,定义为 72.27/25.4 = 2.845276(geom-.r 中的第 165 行):

> 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 对应于 ggplot2 大小单位中的 0.8/2.141959 = 0.3734899。

关于r - ggplot2中的线宽(大小)是如何定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com