仍然需要在ggplot中生成发布级图形。这些天来,在我提交的期刊中,这意味着将数字保存为.eps格式。 This帮助很大,但是现在我遇到了一个新问题。我在图表的每个单独方面的标题上都需要希腊字母mu和sigma。这是示例代码
library(bayesplot)
df <- data.frame(xVar = rnorm(1e4,0,1), yVar = rnorm(1e4,2,1), zVar = rnorm(1e4,4,1))
t <- bayesplot::mcmc_trace(df)
t
现在,我们可以使用Unicode将变量重命名为我们想要的希腊字符,
library(dplyr)
df %<>% rename("\u03BC x" = "xVar", "\u03BC y" = "yVar", "\u03BC z" = "zVar")
names(df)
[1] "μ x" "μ y" "μ z"
然后重新运行ggplot
t <- bayesplot::mcmc_trace(df)
t
这些作为.png很好出现
ggplot2::ggsave(filename = "tPlot.png",
plot = t,
device = "png",
dpi = 1200,
width = 15,
height = 10,
units = "cm")
但是在渲染为.eps时
ggplot2::ggsave(filename = "tPlot.eps",
plot = t,
device = "eps",
dpi = 1200,
width = 15,
height = 10,
units = "cm")
希腊字符显示为..
(SO不支持.eps数字)
我收到以下警告消息
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
conversion failure on 'μ x' in 'mbcsToSbcs': dot substituted for <ce>
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
conversion failure on 'μ x' in 'mbcsToSbcs': dot substituted for <bc>
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
conversion failure on 'μ y' in 'mbcsToSbcs': dot substituted for <ce>
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
在Rhelp上的this帖子中,建议的答案之一是“ encoding =“ Greek”和family =“ URWHelvetica”,并确保 您的查看器能够支持该字体。”
所以我尝试了
postscript(file = "tPlot.eps", encoding = "Greek", family = "URWHelvetica")
然后重新运行代码,但是得到了相同的警告。
过去,当我进入这个阶段时,我感到很沮丧,并用graphpad棱镜复制了这些图形,但是现在我决定以某种方式对其进行解决。
所以如何获取希腊字符或数学符号以呈现为.eps ?