推 GauYi:我有一個學妹沒有胸部12/28 19:56
推 VVVV5555:哈哈。你真有才12/28 19:56
→ rs5556:難怪他們沒被嚇跑 哈哈12/28 19:56
→ VVVV5555:這邊只剩下一堆無聊影片。但你讓我笑了,你真的很不一樣12/28 20:00
→ VVVV5555:五樓帥哥12/28 20:00
→ VVVV5555:哈哈XD你幹嘛說出來12/28 20:01
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.82.45.171
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1508133616.A.70A.html
→ celestialgod: windows? linux? 10/17 20:50
→ celestialgod: windows的話 搭配showtext可以用但是圖很悲劇 10/17 21:50
→ celestialgod: linux的話直接上沒問題... 10/17 21:51
> -------------------------------------------------------------------------- <
W作者: celestialgod (天) 看板: R_Language
標題: Re: [問題] GGplot ggsave用cairo不能存字型?
時間: Tue Oct 17 22:11:19 2017
※ 引述《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
※ 編輯: celestialgod (111.246.26.81), 10/17/2017 22:14:17