【发布时间】:2021-11-23 05:09:12
【问题描述】:
我想保存以下情节:
library(ggplot2)
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab(expression(~delta^13*C~"[\211]"))
ggsave(myplot,
filename = "myplot.png",
type = "cairo")
但我收到以下错误:
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
Metric information not available for this family/device
问题必须是表达式和 unicode 的组合,因为这两个工作:
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab("[\211]")
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab(expression(~delta^13*C))
我该如何解决这个问题?
编辑:我想打印“per mille”符号。显然它的 unicode 是 U2030,我错误地认为“\211”是一个 unicode,但肯定是别的东西。
编辑 2: 同时,我发现 this question 有类似的问题。在那里,一个建议是用encoding = "MacRoman" 保存情节,不幸的是这对我不起作用:
Error in png_dev(..., res = dpi, units = "in") :
unused argument (encoding = "MacRoman")
编辑 3:
> capabilities()["cairo"]
cairo
TRUE
> sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] patchwork_1.1.1 ggplot2_3.3.5 dplyr_1.0.7
【问题讨论】:
-
你试过
\u211或\u0211吗?这就是我添加 unicode 符号的方式。至少在我的机器上可以正常工作。 -
@stefan 嗯,当我尝试时, [] 被打印为轴标签。知道我做错了什么吗?
-
"[\u211]"也适合我。你用的是什么字体? -
@RobinGertenbach 默认设置(我认为是 Arial?)。但我怀疑这是字体问题,因为它本身就可以工作,只是与
expression的组合没有。