【问题标题】:Saving ggplot as .eps将 ggplot 保存为 .eps
【发布时间】:2019-08-13 12:52:05
【问题描述】:

我在 ggplot 中制作出版级数字的问题仍在继续(请参阅here

这是一些引发错误的可重现代码。

library(bayesplot)
df <- data.frame(xVar = rnorm(1e4,0,1))
t <- bayesplot::mcmc_trace(df,"xVar")
t

一切都好。但是当我尝试将数字保存为 eps 时(许多期刊要求)

ggplot2::ggsave(filename = "tPlot.eps", 
                plot = t1, 
                device = "eps", 
                dpi = 1200, 
                width = 15,
                height = 10, 
                units = "cm")

我得到了错误

Error in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) : 
  family 'serif' not included in postscript() device

有没有人遇到过此类问题并找到解决方案?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    绘图中的字体在R 中是一个棘手的话题。您可能没有字体或R 根本找不到它。您可以查看extrafont 包并尝试在您的系统上寻找字体或下载它。不过,我宁愿建议简单地选择一个不同的主题:

    library(bayesplot)
    df <- data.frame(xVar = rnorm(1e4,0,1))
    t <- bayesplot::mcmc_trace(df,"xVar") +
      ggplot2::theme_bw()
    t
    
    ggplot2::ggsave(filename = "tPlot.eps", 
                    plot = t, 
                    device = "eps", 
                    dpi = 1200, 
                    width = 15,
                    height = 10, 
                    units = "cm")
    

    这消除了我机器上的错误。

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 2019-10-26
      • 1970-01-01
      相关资源
      最近更新 更多