将Unicode字符保存到R中的.pdf [英] Save unicode characters to .pdf in R

查看:35
本文介绍了将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...

尝试对其进行修复

  1. 我尝试在 ggsave ->中使用 cairo_pdf 设备.没用.
  2. 使用此帖子绘制unicode字符,但不太理解它...
  1. I tried to use the cairo_pdf device in ggsave -> didn't work.
  2. 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")

使用此处的建议: https://stackoverflow.com/a/44548861/1827

这篇关于将Unicode字符保存到R中的.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆