ggplot2:理解点的大小

地学

我试图了解 ggplot/grid 如何确定要渲染的点大小。这个答案(来自 Hadley 的评论)描述了.pt 幻数常数的作用,但我看不出这些数字是如何加起来的。这表明:

# empty ggplot obj with no margins outside panel
p0 = ggplot() + scale_size_identity() +
  scale_y_continuous(expand = c(0,0)) + scale_x_continuous(expand = c(0,0)) +
  theme(axis.text = element_blank(), panel.grid = element_blank(),
        panel.border = element_rect(colour='black', fill='transparent'),
        panel.spacing = unit(0, 'mm'), axis.ticks.length = unit(0, "mm"),
        plot.margin=unit(c(0,0,0,0), "mm")) + labs(x=NULL, y=NULL)

# 2 data points plus 2 corner points to define bbox ('limits' args seem to force extra margins)
d = data.frame(x = 1:4, y = c(100,150,250,300), sz = c(0,76.15,76.15,0))

p = p0 + geom_point(data=d, aes(x, y, size=sz), fill='red', stroke=0, shape=22, alpha=.8)

# output to pdf and open
fn='test.pdf'; ggsave(p, filename = fn, w=6, h=4, units = "in"); browseURL(fn)

在此处输入图片说明

76.15通过反复试验确定了尺寸这个尺寸让两个方点刚好接触,但我不明白为什么。该图为 6 英寸宽 = 152.4 毫米。要满足,点必须为 2 英寸宽 = 50.8 毫米。但我看不到 76.15 尺寸如何通过.pt乘数 (2.845276)映射到 50.8mm

任何建议非常感谢。我应该补充一点,当使用shape=1522 而不是 22,相同结果的点大小是67.15,但我不确定这会让我们更接近答案。

巴蒂斯特

您可能会发现这个旧线程很有用:http : //r.789695.n4.nabble.com/Fwd-R-size-of-point-symbols-td923507.html

本质上:计算点形状大小的唯一可用参考是源代码(src/main/engine.c

case  22: /* squares */
    xc = toDeviceWidth(RADIUS * SQRC * GSTR_0, GE_INCHES, dd);
    yc = toDeviceHeight(RADIUS * SQRC * GSTR_0, GE_INCHES, dd);
    GERect(x-xc, y-yc, x+xc, y+yc, gc, dd);
    break;

形状 0,1,4,7,8,10,12,13,14,15,16,18,19,21 似乎受到按比例缩小 0.75 倍的正方形的约束,

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章