将Unicode字符保存到R中的.pdf
问题描述:
我想使用 ggsave
将特定的unicode字符保存到pdf文件中.
I would like to save specific unicode characters to a pdf file with ggsave
.
示例代码
library(ggplot2)
ggplot() +
geom_point(data = data.frame(x=1, y=1), aes(x,y), shape = "\u2191") +
geom_point(data = data.frame(x=2, y=2), aes(x,y), shape = "\u2020")
ggsave("test.pdf", plot = last_plot()), width = 40, height = 40, units = "mm")
但是,当保存 .pdf
时,unicode字符将转换为三个点...
However, when saving the .pdf
the unicode characters are transformed to three dots...
尝试对其进行修复
- 我尝试在
ggsave
->中使用cairo_pdf
设备.没用. - 使用此帖子绘制unicode字符,但不太理解它...
- I tried to use the
cairo_pdf
device inggsave
-> didn't work. - Used this post to plot the unicode characters, but didn't quite understand it...
问题
如何在pdf中同时使用两个unicode字符?
How do I use both unicode characters in a pdf?
> sessionInfo()
R version 3.6.2
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.5
答
这似乎在我的Mac上有效:
This seems to work on my mac:
library(tidyverse)
quartz(type = 'pdf', file = 'test.pdf')
ggplot() +
geom_point(data = data.frame(x=1, y=1), aes(x,y), shape = "\u2191") +
geom_point(data = data.frame(x=2, y=2), aes(x,y), shape = "\u2020")