问题描述
我正在使用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 :
对于标准地块:
对于具有ggplot2的图:
For plots with ggplot2 :
欢迎提出任何有关如何继续查找问题并解决问题的建议?
Any suggestions how I can proceed to find the problem and solved are welcome?
我已经尝试过的以下步骤:
The following steps I already have tried :
- 转到字体"书和禁用的反应字体.重新启动计算机
- 将R升级到R 3.6.0.
- 对于标准绘图,每次都可以使用
par(family = "Arial")
作为解决方法,但这不适用于ggplot2. - 在字体书中重新安装了标准字体.
- 我在R中安装了extrafont软件包.键入fonts()时,所有字体都显示为已安装.
- Go to the Font book and reactive disabled font. Restart computer
- Upgrading R to R 3.6.0.
- I can use
par(family = "Arial")
as a workaround each time for standard plots, but this won't work for ggplot2. - Reinstalled standard fonts in font book.
- 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
并行,这是使用 showtext
.
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找不到要在绘图中使用的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!