0

我正在尝试将 ≤ 符号嵌入到我的 pdf 绘图的字体中。p1在 RStudio ( ) 中查看时,图中会显示 ≤ 符号。但是,当我保存绘图并嵌入字体时,≤ 符号将转换为 = 符号。

使用 extrafont 包我想用 CM Roman 字体保存我的情节。我已经尝试了将设备设置cairo_pdfggsave(). 这将 ≤ 符号嵌入到 pdf 中,但字体不再是 CM Roman。

需要做什么才能使 ≤ 符号保留在图中并且字体为 CM Roman?

library(ggplot2)
library(extrafont)

font_import()
font_install("fontcm")
loadfonts()

df <- data.frame(foo = c(2, 4, 8 , 16),
                 bar = factor(c(1:3, "4\u2264")))


p1 <- ggplot(df, aes(x = bar, y = foo)) + 
  geom_bar(stat="identity") +
  labs(title = "p1: Equality sign shows in RStudio plot") +
  theme(text = element_text(family = "CM Roman", size = 25))

p2 <- ggplot(df, aes(x = bar, y = foo)) + 
  geom_bar(stat="identity") +
  labs(title = "p2: Equality sign not shown in .pdf file") +
  theme(text = element_text(family = "CM Roman", size = 25)) 

print(p1)
[![p1 plot][1]][1] # there should be an image of p1 here...

# Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.53.3/bin/gswin64c.exe") #~ run once at start of each R session  
ggsave("p2.pdf", p2, width = 15, height = 10, units = "in")
embed_fonts("p2.pdf", outfile="p2.pdf")
[![p2 plot][1]][1] # there should be an image of p2 here...
4

1 回答 1

0

ggsave 从 ggplot+gridExtra 丢失 unicode 字符

这篇文章有几个解决方案。我认为它必须与编码有关,但我不是 100% 确定。

于 2021-01-29T08:27:37.813 回答