R 找不到要用于绘图的字体

标签 r macos

我使用的是 R 3.5.2。在 Mac Mojave 10.14.4 上。由于几天在我的标准图中出现文本问题。使用 ggplot 绘图也不起作用。我收到消息说:

对于标准图:

Warning messages: 1: In doTryCatch(return(expr), name, parentenv, handler) : no font could be found for family "Arial"



对于带有 ggplot2 的图:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,
: polygon edge not found



欢迎提出我如何继续查找问题并解决的任何建议?

我已经尝试过以下步骤:
  • 转到字体书和 react 禁用字体。重启电脑
  • 将 R 升级到 R 3.6.0。
  • 我可以用 par(family = "Arial")每次都作为标准绘图的解决方法,但这不适用于 ggplot2。
  • 在字体簿中重新安装了标准字体。
  • 我在 R 中安装了包 extrafont。当输入 fonts() 时,所有字体都显示已安装。

  • 根据 MacOSX,字体已全部安装、事件且不存在重复项,但我仍然无法使用 R 访问它们。

    这是我正在测试的代码:
    x <- seq(1, 10,1)
    y <- rnorm(10, 4,1)
    plot(y~x)
    
    library(ggplot2)
    
    # Basic normal curve
    p  <- ggplot(data.frame(x = c(-4, 4)), aes(x = x)) +
      stat_function(fun = dnorm, size=1.5)
    p
    

    最佳答案

    平行于 extrafont ,这是使用 showtext 的解决方案.

    library(showtext)
    font_add("Arial", "/Library/Fonts/Arial.ttf")  # Use the actual file path
    showtext_auto()
    
    x <- 1:10
    y <- rnorm(10, 4, 1)
    pdf("plot1.pdf")
    plot(y ~ x, family = "Arial")
    dev.off()
    
    library(ggplot2)
    # Basic normal curve
    p <- ggplot(data.frame(x = c(-4, 4)), aes(x = x)) +
        stat_function(fun = dnorm, size = 1.5) +
        theme(text = element_text(family = "Arial"))
    ggsave("plot2.pdf", p)
    

    关于R 找不到要用于绘图的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55933524/

    相关文章:

    html - 是否有适用于 Mac 的半途而废的免费 HTML 编辑器?

    iphone - 使用 iPhone SDK SSH 连接到 Mac 进行远程登录

    r - 突出显示 ggplot2 中的特定点

    regex - 如何对包含给定单词的句子向量进行子集化

    R pROC 精度

    r - 从命名列表和函数名创建可解析的字符串

    macos - 警告 : Calling `sha256 "digest"with Brew on macOS

    eclipse - 无法在macOS Big Sur上运行Eclipse

    r - 如何将格式化格式应用于多列?

    OS X 上的 Python : Getting local date time patterns