簡體   English   中英

ggplot 中的字體更改不適用於 biplot label 名稱

[英]Font change in ggplot not working on biplot label names

我偶然發現了一個問題,我可以將雙標圖像中的所有文本更改為另一種字體,標簽除外。

下面是一個簡單的問題示例,label 文本明顯不同:

我使用的代碼也附上。 我找不到解決此問題的方法,希望有人可以提供幫助。

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 在此 function 中,您可以使用font.family參數指定字體系列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM