gpt4 book ai didi

R 在轴表达式中导出带有 unicode 的 ggplot 对象时崩溃

转载 作者:行者123 更新时间:2023-12-02 04:30:03 25 4
gpt4 key购买 nike

这段代码

    data = data.frame(A=c(1:100), B=runif(100))
library(ggplot2)
ggplot(data, aes(A, B)) +
geom_point() +
ylab(expression(paste(delta^{13}~"C"~"VDPB (\u2030/)"))) +
xlab("Time (Days)")
ggsave("test.pdf", width=4, height=4, dpi=300, device=cairo_pdf)

导致我的 R-Session 崩溃

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
Metric information not available for this family/device

尽管表达式在 R-Studio 图形设备上正确绘制。

经过google后,这个问题是已知的,但我还没有找到解决方案。有什么办法可以避免这个问题吗?

/编辑: session 信息

    R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] Cairo_1.5-9 rvg_0.1.2 scales_0.4.1 gridExtra_2.2.1 RColorBrewer_1.1-2
[6] reshape_0.8.6 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 digest_0.6.12 assertthat_0.1 R.methodsS3_1.7.1 grid_3.3.3
[6] plyr_1.8.4 gtable_0.2.0 gdtools_0.1.3 lazyeval_0.2.0 R.oo_1.21.0
[11] R.utils_2.5.0 xml2_1.1.1 labeling_0.3 tools_3.3.3 munsell_0.4.3
[16] colorspace_1.3-2 tibble_1.2

最佳答案

旧(好的)答案:将 ggsave("test.pdf", width=4, height=4, dpi=300, device=cairo_pdf) 更改为 ggsave("test.pdf") pdf”,宽度=4,高度=4,dpi=300,设备=“pdf”)。我刚刚更换了设备。

编辑:如果将 ylab 创建更改为 ylab(sprintf(paste(delta^{13}~"C"~"VDPB (\u2030/)")))表达式更改为sprintf。但是,您的 y 标签不会完全显示。看来您正在使用 cairo_pdf 不喜欢的一些字符。这样可以进一步解决问题的根源。

关于R 在轴表达式中导出带有 unicode 的 ggplot 对象时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42722446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com