【问题标题】:ggplot2: Degree Celsius Symbol in labeller with dev="tikz" option in knitrggplot2:在 knitr 中带有 dev="tikz" 选项的贴标机中的摄氏度符号
【发布时间】:2016-07-12 12:49:17
【问题描述】:

我想在ggplot2 labeller 中加入摄氏度符号。下面给出了 MWE 及其输出:

library(ggplot2)
ggplot(data=mtcars, mapping = aes(x=drat, y=mpg)) + geom_point() +
  facet_wrap(facets = ~cyl, labeller = as_labeller(c(`4` = "4 °C",`6` = "6 °C", `8` = "8 °C")))

但是,当在knitr 中使用dev="tikz" 选项时,相同的策略不起作用。

【问题讨论】:

    标签: r ggplot2 knitr tikz tikzdevice


    【解决方案1】:

    使用 tikz 设备时,一种选择似乎是用原生乳胶编写数学。 \circ 是度数符号,因此您的标签之一可能是 "$4^\\circ{C}$"

    以下内容使用dev = "tikz" 编织成 PDF 并显示度数符号:

    ggplot(data=mtcars, mapping = aes(x=drat, y=mpg)) + geom_point() +
      facet_wrap(facets = ~cyl, 
             labeller = as_labeller(function(string) paste0("$", string, "^\\circ{C}$")))
    

    要在数字和度数符号之间添加更多间距,您可以在标签中包含 \\:\\;

    labeller = as_labeller(function(string) paste0("$", string, "\\;^\\circ{C}$"))
    

    【讨论】:

      猜你喜欢
      • 2011-03-19
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      相关资源
      最近更新 更多