将绘图导出为带有 utf8 字符的 pdf

Export plot as pdf with a utf8 character

当我以pdf格式保存绘图时,标签中的utf8字符没有出现。当我在 RStudio 中使用 "Export" 按钮时它不会出现,当我将此代码包含在带有 pdf 图形输出的 Sweave 文档中时它也不会出现。我的问题是使用 Sweave(不是 knitr)获得正确的 pdf 输出。 (如果我找不到解决方案,我会用 tikzDevice 生成它)

ylab <- expression(paste("", bar(italic("\u2113")), "(",phi[0], "|", italic(list(x,y)), ")"))
plot(0,0, ylab=ylab)

编辑

展示了如何将其集成到自定义图形设备中。


这似乎使用 CairoPDF() frm Cairo 包使用 ubuntu14.04,R3.2.1.EDIT 在评论中来自 Stephane 的渲染:如果CairoPDF() 不起作用,然后尝试 cairo_pdf()

一些 sweave 代码(使用 Rstudio)

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<Export_plot, echo=FALSE>>=
library(Cairo)

CairoPDF("test.pdf")
par(mar=c(6,6,6,6))
ylab <- expression(paste("", bar(italic("\u2113")), "(",phi[0], "|", italic(list(x,y)), ")"))
plot(0,0, ylab=ylab, cex.lab=2)
invisible(dev.off())

@

%Plot
\includegraphics[width=6cm]{test.pdf}

\end{document}

这是我得到的 pdf 输出(注意分辨率是垃圾,因为我已经通过 gimp 将它转换为 png)