Re: [問題] GGplot ggsave用cairo不能存字型?

作者: celestialgod (天)   2017-10-17 22:11:19
※ 引述《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
作者: ruokcnn (Dean)   2017-10-20 19:38:00
感謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com