ggplot 中的字体更改不适用于双标标签名称

问题描述

我偶然发现了一个问题,我可以将双标图图像中的所有文本更改为另一种字体,标签除外。

问题的一个简单示例如下所示,标签文本明显不同:

我使用的代码也附上了。我找不到此问题的解决方案,希望有人可以提供帮助。

p <- fviz_pca(fit,geom = c("point"),repel = TRUE,label = "var",habillage = IOSDV1$Fertilisation,addEllipses = TRUE,ellipse.type="confidence",palette = "npg",labelsize = 5,pointsize = 3,col.ind = "black",col.var = "black",arrowsize = 0.6) + 
  theme_bw(base_family = "Palatino Linotype") + 
  theme(text = element_text(family = "Palatino Linotype",size = 14)) + 
  labs(title = "")

ggsave(filename = "ggplot_garamond.png",dpi = 600,type = "cairo")

解决方法

回答

您必须将 font.family 参数添加到 fviz_pca

fviz_pca(fit,geom = c("point"),repel = TRUE,label = "var",habillage = IOSDV1$Fertilisation,addEllipses = TRUE,ellipse.type="confidence",palette = "npg",labelsize = 5,pointsize = 3,col.ind = "black",col.var = "black",arrowsize = 0.6,font.family = "Palatino Linotype")

基本原理

在内部,fviz_pca 调用 fviz,后者又调用 ggpubr::ggscatter。在此函数中,您可以使用 font.family 参数指定字体系列。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...