R找不到要在绘图中使用的字体 [英] R can not find fonts to be used in plotting

查看:404
本文介绍了R找不到要在绘图中使用的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R 3.5.2.在Mac Mojave 10.14.4上.几天以来,我的标准绘图中的文字出现问题.用ggplot绘制图也不起作用.我收到消息说:

I was using R 3.5.2. on Mac Mojave 10.14.4. Since a couple days have problems with text in my standard plots. Drawing plots with ggplot doesn't work either. I'm getting messages saying :

对于标准地块:

警告消息: 1:在doTryCatch(return(expr),name,parentenv,handler)中: 找不到"Arial"家族的字体

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

对于具有ggplot2的图:

For plots with ggplot2 :

grid.Call(C_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,
中的错误 :找不到多边形边缘

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

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

Any suggestions how I can proceed to find the problem and solved are welcome?

我已经尝试过的以下步骤:

The following steps I already have tried :

  1. 转到字体"书和禁用的反应字体.重新启动计算机
  2. 将R升级到R 3.6.0.
  3. 对于标准绘图,每次都可以使用par(family = "Arial")作为解决方法,但这不适用于ggplot2.
  4. 在字体书中重新安装了标准字体.
  5. 我在R中安装了extrafont软件包.键入fonts()时,所有字体都显示为已安装.
  1. Go to the Font book and reactive disabled font. Restart computer
  2. Upgrading R to R 3.6.0.
  3. I can use par(family = "Arial") as a workaround each time for standard plots, but this won't work for ggplot2.
  4. Reinstalled standard fonts in font book.
  5. I installed the packages extrafont in R. When typing fonts() all fonts are shown to be installed.

根据MacOSX,所有字体均已安装,有效且没有重复出现,但我仍然无法使用R来访问它们.

According MacOSX the fonts are alle installed, active and no duplicates present, but I still can't access them with R.

这是我正在测试的代码:

This is the code I'm testing with :

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并行,这是使用

Parallel to extrafont, here is the solution using 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找不到要在绘图中使用的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆