首页>Program>source

我无法在网上找到答案的快速问题(或威克姆的书):

ggplot2中size参数的单位是什么? 例如geom_text(size = 10)-以10为单位?

编辑:同一问题适用于ggsave(height = 10,width = 10)中的默认单位

最新回答
  • 2021-1-12
    1 #

    答案是:单位是点.它是 grid中fontsize的单位 包.在 ?unit ,我们发现以下定义

    "points" Points. There are 72.27 points per inch.
    

    (但请注意紧密相关的" bigpts" Big Points. 72 bp = 1 in.

    内部 ggplot2 将字体大小乘以魔数 ggplot2:::.pt ,定义为 1/0.352777778

    这里有个演示,我使用grid和ggplot2创建了一个大小相同的字母:

    library(grid)
    library(ggplot2)
    ggplot(data=data.frame(x=1,y=1,label=c('A'))) +
      geom_text(aes(x,y,label=label),size=100)
    ## I divide by the magic number to get the same size.
    grid.text('A',gp=gpar(fontsize=100/0.352777778,col='red'))
    

    附录感谢@baptiste

    "幻数"(在aaa-constants.r中定义为.pt<-1 / 0.352777778)实际上只是"点"和" mm"之间的转换因子,即 1/72 * 25.4 = 0.352777778 .不幸的是, grid 对" pts"和" bigpts"进行了细微的区分,这解释了为什么 convertUnit(unit(1, "pt"), "mm", valueOnly=TRUE) 给出了 0.3514598的稍微不同的值

  • 2021-1-12
    2 #

    'ggplot2'包(如之前的'lattice')是在 grid上构建的 包.您可以在以下位置获得可用的单位:

    ?grid::unit
    ?grid::convertX
    ?grid::convertY
    grid::convertX(grid::unit(72.27, "points"), "inches")
    

    (我使用形式主义 pkg::func 因为在大多数情况下, 加载了一个名称空间,但在任一 grid时均未附加 或`ggplot2已加载。)

    我之前发布了一条评论,后来我删除了评论,说 lattice 很有意思.我看到 size的文本大小后才这样做 大约是10毫米 agstudy提到的"魔术"数实际上在以下值的1%之内:

    size=10
    

  • 2021-1-12
    3 #

    来自 as.numeric(grid::convertX(grid::unit(1, "points"), "mm")) #[1] 0.3514598 0.352777778/.Last.value #[1] 1.00375

    ?aes_linetype_size_shape
    

    # Size examples # Should be specified with a numerical value (in millimetres), # or from a variable sourceheight 在ggsave中与 width有关 来自 par("din")

    ?par
    
    

    所以我猜 din R.O.; the device dimensions, (width, height), in inches. See also dev.size, which is updated immediately when an on-screen device windows is re-sized.size 以毫米和 aes ggsaveheight 英寸。

    width

  • 保留git --assume在分支检出之间保持不变的文件
  • python:如何用单反斜杠转义字符串的特殊字符