我有一个使用非标准字体生成ggplot的短脚本(请参见下面的MWE)。
如果我在R(即RStudio)中运行脚本,那么一切都按预期工作,并且没有看到任何错误。
当我使用命令行和
Rscript
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
Calls: <Anonymous> ... drawDetails -> drawDetails.text -> grid.Call.graphics
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted
我使用
Rscript myscript.R
,脚本的内容是
library(ggplot2)
theme_set(theme_light(base_family = "LM Roman 10"))
# if "base_family" is left empty, everything works with Rscript
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point()
ggsave("myplot.pdf", p, device = cairo_pdf)
我使用Ubuntu18.04.1和R3.5.1。我还更新了我所有的软件包。
R CMD BATCH myscript.R
一切都很好。
如果您有相同的问题(到目前为止,我还无法解决),我已恢复使用
R CMD BATCH --vanilla myscript.R
.