提问人:jay.sf 提问时间:10/8/2023 最后编辑:jay.sf 更新时间:10/9/2023 访问量:44
如何在 pdf 中使用 UTF-8 编码的字符向量?
How to use UTF-8-encoded character vectors in pdf?
问:
尝试将整数转换为 UTF-8 编码的字符向量,使用 to set .intToUtf8
pch=
(.pch <- c(intToUtf8(9675), intToUtf8(9679)))
# [1] "○" "●"
虽然它适用于,png
png('foo.png', 400, 400)
with(df, plot(x, y, pch=.pch[(z < 0) + 1], xlim=0:1, ylim=0:1))
legend('topleft', pch=.pch, legend=letters[1:2])
dev.off()
它不会为,pdf
pdf.options(encoding='ISOLatin2.enc')
pdf('foo.pdf', 4, 4)
with(df, plot(x, y, pch=.pch[(z < 0) + 1], xlim=0:1, ylim=0:1))
legend('topleft', pch=.pch, legend=letters[1:2])
dev.off()
但我想要.pdf
也试图无济于事。'ISOLatin1.enc'
> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Europe/Zurich
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1
数据:
df <- structure(list(x = c(0.2, 0.6, 0.7, 0.9), y = c(0.4, 0.7, 0.9,
0.5), z = c(-1, -1, 1, 1)), class = "data.frame", row.names = c(NA,
-4L))
答:
1赞
SamR
10/8/2023
#1
我在 R 中的绘图中发现的 UTF-8 字符的一种解决方法是使用 ,文档状态可以(在合适的平台上)包含更广泛的 UTF-8 字形,并嵌入使用的字体。pdf
grDevices::cario_pdf()
grDevices::cairo_pdf('foo.pdf', 4, 4)
with(df, plot(x, y, pch=.pch[(z < 0) + 1], xlim=0:1, ylim=0:1))
legend('topleft', pch=.pch, legend=letters[1:2])
dev.off()
注意矢量与位图输出
文档还指出:
请注意,与 postscript 和 pdf 不同,有时记录位图而不是矢量图形。
cairo_pdf
cairo_ps
我不太确定“有时”是什么意思。在这种情况下,我不会发生这种情况:结果是一个矢量图形。但是,您可能希望检查您的环境中是否也存在这种情况。
评论