so I want add some charm to my plots by changing the fonts. But my RStudio always crashes as I try to save as a pdf. So lets take this data:
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")
Then using the Export>>Save as pdf function, the image with the different fonts will not save. Also using the pdf("SampleGraph.pdf",width=7,height=5)
Does not work. Doesnt anyone know of a way around this issue, or is it my computer got out of the wrong side of bed today?
It seems that .pdf format cannot handle those fonts. One solution would be to export the image as a .png format and use Sweave to include the figure in the .pdf. Alternatively, you could convert the .png to a .pdf using a program such as Foxit Reader or ImageMagick. I'll demonstrate the Sweave solution.
\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}
This produces the following .pdf file.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With