【问题标题】:Export plot as pdf with a utf8 character将绘图导出为带有 utf8 字符的 pdf
【发布时间】:2015-09-13 13:32:00
【问题描述】:

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

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

【问题讨论】:

  • Cairo 包中尝试CairoPDF()

标签: r pdf graphics utf-8 sweave


【解决方案1】:

编辑

Follow up question: custom graphical device in sweave 展示了如何将其集成到自定义图形设备中。


这似乎使用 CairoPDF() frm 使用 ubuntu14.04、R3.2.1 的 Cairo 包进行渲染。EDIT from Stephane in the cmets:如果 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)

【讨论】:

  • 我在 Ubuntu 14.04、R 3.1.3 下,这不起作用(我得到一个减号而不是“ell”),即使在控制台中(在 Sweave 之外)跨度>
  • 奇怪.. 我得到一个 ell bar 吗?生病张贴图片
  • 当我将CairoPDF 替换为cairo_pdf 时,它终于可以工作了。
  • 也许你可以在你的答案中提出cairo_pdf 作为替代方案,以便我检查标记以接受它。
  • 太好了,您找到了解决方案 Stephane ...我已经编辑了答案。 Mayve 这与 tex 版本有关,为什么 CairoPDF 不起作用???但是非虚拟机
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-20
  • 2020-03-17
  • 1970-01-01
  • 2011-04-10
相关资源
最近更新 更多