看板 R_Language 關於我們 聯絡資訊
※ 引述《ruokcnn (Dean)》之銘言: : [問題類型]: : 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) : [軟體熟悉度]: : 入門(寫過其他程式,只是對語法不熟悉) : [問題敘述]: : 為了ggplot抗鋸齒輸出 ,小弟找到可以用type = "cairo"包在ggsave裡面 : 但只要有包原本嵌好的字型在存的時候就會被打回新細明體 : 令人好不傷心 : 想請問有沒有一兼二顧,摸蛤仔兼洗褲的方式呢? : 還是只能把dpi調爆高看起來比較沒鋸齒? : [程式範例]: : [環境敘述]: : R3.3.3 : [關鍵字]: : GGplot : cairo : 字型 Linux: # centos 7 要先yum install -y google-noto-cjk-fonts library(ggplot2) library(Cairo) df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30)) g <- ggplot(df, aes(gp, y)) + geom_point() + labs(title = "中文測試") + theme(text = element_text(family = "Noto Sans CJK TC")) ggsave("tmp1.png", g) # https://imgur.com/f5fALCa ggsave("tmp2.png", g, type = "cairo") # https://imgur.com/3LtezUk Windows: library(ggplot2) library(Cairo) library(showtext) showtext.auto() df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30)) g <- ggplot(df, aes(gp, y)) + geom_point() + labs(title = "中文測試") + theme(text = element_text(family = "Noto Sans CJK TC")) ggsave("tmp1.png", g) # https://imgur.com/T9XGpxd ggsave("tmp2.png", g, type = "cairo") # https://imgur.com/1FRfOWU # windows正常情況: windowsFonts("Noto Sans CJK TC Regular" = windowsFont("Noto Sans CJK TC Regular")) df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30)) g <- ggplot(df, aes(gp, y)) + geom_point() + labs(title = "中文測試") + theme(text = element_text(family = "Noto Sans CJK TC Regular")) ggsave("tmp3.png", g) # https://imgur.com/7Z56rCj -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.246.26.81 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1508249482.A.7F9.html
ruokcnn: 感謝! 10/20 19:38
※ 編輯: celestialgod (118.170.51.127), 10/21/2017 22:11:46