作者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://webptt.com/cn.aspx?n=bbs/R_Language/M.1508249482.A.7F9.html
1F:推 ruokcnn: 感谢! 10/20 19:38
※ 编辑: celestialgod (118.170.51.127), 10/21/2017 22:11:46