【问题标题】:saving as pdf from Rstudio从 Rstudio 保存为 pdf
【发布时间】:2015-11-12 15:05:04
【问题描述】:

所以我想通过更改字体为我的情节增添一些魅力。但是当我尝试另存为 pdf 时,我的 RStudio 总是崩溃。因此,让我们获取这些数据:

plot(1:10,1:10,type="n")
windowsFonts(
  A=windowsFont("Arial Black"),
  B=windowsFont("Bookman Old Style"),
  C=windowsFont("Comic Sans MS"),
  D=windowsFont("Symbol")
)
text(3,3,"Hello World Default")
text(4,4,family="A","Hello World from Arial Black")
text(5,5,family="B","Hello World from Bookman Old Style")
text(6,6,family="C","Hello World from Comic Sans MS")
text(7,7,family="D", "Hello World from Symbol") 

然后使用Export>>Save as pdf函数,不同字体的图片将无法保存。也使用pdf("SampleGraph.pdf",width=7,height=5) 不工作。有没有人知道解决这个问题的方法,或者是我的电脑今天从错误的床边走出来了?

【问题讨论】:

  • 您是否已经进行了搜索,或者这是您的第一站?也许开始here

标签: r pdf plot


【解决方案1】:

.pdf 格式似乎无法处理这些字体。一种解决方案是将图像导出为.png 格式并使用Sweave 将图形包含在.pdf 中。或者,您可以使用 Foxit Reader 或 ImageMagick 等程序将 .png 转换为 .pdf。我将演示 Sweave 解决方案。

\documentclass{article}

\usepackage[margin=1.0in]{geometry}

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

<<echo=FALSE>>=
par(mar=c(3,3,3,3))
png("test.png", units="in", width=8, height=8, res=500)
plot(1:10,1:10,type="n",xlab="",ylab="")
windowsFonts(
    A=windowsFont("Arial Black"),
    B=windowsFont("Bookman Old Style"),
    C=windowsFont("Comic Sans MS"),
    D=windowsFont("Symbol")
)
text(3,3,"Hello World Default")
text(4,4,family="A","Hello World from Arial Black")
text(5,5,family="B","Hello World from Bookman Old Style")
text(6,6,family="C","Hello World from Comic Sans MS")
text(7,7,family="D", "Hello World from Symbol") 
x <- dev.off()
@

\begin{figure}[ht]
\includegraphics[width=1.0\textwidth]{test}
\end{figure}

\end{document}

这会产生以下.pdf 文件。

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2018-08-22
    相关资源
    最近更新 更多