使用Mac
我使用ggplot2创建了一个图表并将其导出为pdf。 在我将pdf加载到PowerPoint幻灯片之前,一切似乎都没问题 - 由于某种原因,轴'标签和文本消失了。
我觉得它与字体有关(必须是Arial ..)但我不明白为什么会这样。
以下是代码:
library(ggplot2)
library(extrafont)
loadfonts()
theme_set(theme_bw())
df <- mtcars
gg <- ggplot(df, aes(x = mpg, y = cyl)) +
geom_point(
aes(col = carb),
size = 2,
position = position_jitter(width = 0, height = .09),
show.legend = F
) +
geom_hline(
yintercept = mean(df$cyl),
linetype = "dashed",
size = 0.5,
colour = "gray80"
) +
theme(
panel.border = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(colour = "navy"),
axis.title = element_text(colour = "navy"),
axis.text = element_text(colour = "navy"),
text = element_text(family = "Arial")
) +
labs(y = "hey", x = "jude")
plot(gg)
ggsave("test.pdf", gg ,width = 20, height = 12, units = "cm")
更新:删除text = element_text(family = "Arial")
似乎“解决”了问题,但我仍然需要能够更改文本的字体,因此它并没有真正帮助。