Try   HackMD

R 畫畫遇到的問題大整理

中文字體超級難調

以mac電腦為例

解法1

但我自己操作這個方法是失敗的

source1: https://hackmd.io/@LHB-0222/set_ggplot2#更改字體配置

library(extrafont) library(remotes) remotes::install_version("Rttf2pt1", version = "1.3.8") # 要加上面這句是因為直接跑的話會顯示「font family 'XXXX' not found」 font_import("/System/Library/Fonts/") # 要找一下你的字體檔存在哪裡,這句要跑一陣子,如果字體很多的話 #loadfonts() fonts() # 查看字體列表 th <- theme(title = element_text(family="HanaMinA"), text = element_text(family="jf-openhuninn-1.1"), axis.text.y = element_text(family="jf-openhuninn-1.1"), axis.text.x = element_text(family="jf-openhuninn-1.1"), legend.text = element_text(family="jf-openhuninn-1.1"), plot.title = element_text(family="GenYoMin TW TTF SemiBold") )

解法2

我測試成功~

金萱粉圓體下載連結: https://free.com.tw/justfont-huninn/

library(showtext) showtext.auto(enable = TRUE) font_add("jf-openhuninn", "jf-openhuninn-1.1.ttf") # 金萱粉圓體是開源的 th <- theme(title = element_text(family="jf-openhuninn"), text = element_text(family="jf-openhuninn"), axis.text.y = element_text(family="jf-openhuninn"), axis.text.x = element_text(family="jf-openhuninn"), legend.text = element_text(family="jf-openhuninn"), plot.title = element_text(family="jf-openhuninn") )

備註:主要是mac有個基本的問題(我的猜測),可能設定bold(粗體)italic(斜體) 可能會有問題的原因是因為它們可能都被存放在不同的字型檔案之中(?),
所以建議如果要用粗體,就直接把抓該粗體的字型檔案,如下圖示意:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →