Note: I co-authored the package I am about to recommend, so this is a shameless plug.
You can try creating your graphics using the tikzDevivce which lets TeX handle all of the typesetting. This will hopefully sidestep any font issues you are having as the text in your graphics will use the same font as the body text of your paper, which is displaying fine.
To install the package in R:
install.packages('tikzDevice')
Then make your graph as usual, except use tikz()
instead of pdf()
to start the plot output:
require(tikzDevice)
tikz('myAwesomeRPlot.tex')
# Your plotting code here
dev.off()
The output of the tikzDevice is a .tex
file containing commands required to construct your plot using TikZ---an excellent graphics package for TeX, LaTeX and ConTeXt (however, our output is currently only compatible with LaTeX). To include your plot in a paper, use \input
instead of \includegraphics
:
% In your preamble:
\usepackage{tikz}
% Later on in your paper...
\begin{figure}
\input{myAwesomeRPlot}
\caption{Check out the spread on that distribution!}
\end{figure}
You can also pass the standAlone=TRUE
option to tikz()
and the resulting .tex
file will be self-contained and can be typeset by LaTeX without including it in another document.
For more information and examples, check out the package vignette.
Hope this helps!
Addendum
It should be noted that the tikzDevice treats all plot text as LaTeX code. This allows you do do things like:
curve({x^2 / 2},-1,1,main="Plot of $y=\\frac{x^2}{2}$",ylab="$\\frac{x^2}{2}$")
And LaTeX will typeset the equations in your plot. This behavior has some consequences:
The backslash at the beginning of each LaTeX command must be escaped by another backslash as R treats backslashes as escape characters.
Any character that is special to LaTeX, such as #
, $
, %
, ^
, _
, etc, must be escaped if you don't want it treated as a LaTeX command:
plot(...,main="I really want the dollar sign in \\$2.99!")
If LaTeX code in your plot text requires special packages, you need to make the tikzDevice aware of this. See the documentation of tikzLatexPackages
in section 3.1 of the vignette for details.
I will provide you with 6 batch files. Each takes a (La)TeX input file name without extension. It will compile a single (La)TeX input file to produce an output in both PDF and EPS. In development phase, you may compile the same (La)TeX input file with each of the 6 batch files, and investigate which one suits you best. Each of the 6 batch files processes a single (La)TeX input file using different steps internally. The description will be clearer later in the next explanation.
In the production phase, you should have decided which one among them will be applied on a bunch of (La)TeX input files you have. Since applying the batch file on a bunch of (La)TeX input files is very tedious job, I provide you with an additional batch file to automate the process. Thus there are 7 batch files in total.
BatchA.bat
rem batchA.bat
rem echo off
latex -interaction=nonstopmode %1
dvips -R -t unknown %1
ps2pdf -dAutoRotatePages#/None -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress %1.ps %1-temp.pdf
pdfcrop --restricted --hires %1-temp %1.pdf
pdftops -level3 -eps %1.pdf
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1.ps
del %1-temp.pdf
- It can be used for an input file with any paper size.
- Steps:
TEX -> DVI -> PDF -> cropping -> EPS
.
pdfcrop
takes a significant amount of time to do cropping. If you don't need cropping, don't use this batch file.
BatchB.bat
rem batchB.bat
echo off
latex -interaction=nonstopmode %1
dvips -R -t unknown %1
ps2pdf -dAutoRotatePages#/None -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress %1.ps
pdftops -level3 -eps %1.pdf
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1.ps
- It can be used only for an input file with tight paper size.
- Steps:
TEX -> DVI -> PDF -> EPS
.
- It runs faster than
batchA.bat
because no cropping with pdfcrop
. The drawback is you must specify the paper size tightly.
BatchC.bat
rem batchC.bat
echo off
latex %1
dvips -t unknown %1
gswin32c -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%1.pdf %1.ps
pdftops -eps %1.pdf
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1.ps
- It is almost the same as the
batchB.bat
but with fewer switches to speed up the compilation.
- It can be used only for an input file with tight paper size.
- Steps:
TEX -> DVI -> PDF -> EPS
.
- It runs faster than
batchA.bat
because no cropping with pdfcrop
. The drawback is you must specify the paper size tightly.
BatchD.bat
rem batchD.bat
echo off
tex %1
dvips -t unknown %1
gswin32c -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%1.pdf %1.ps
pdftops -eps %1.pdf
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1.ps
- It is almost the same as the
batchC.bat
but using tex.exe
instead of latex.exe
. The input file must be in plain TeX format. I hope it becomes faster than methodC.bat
, but it has not been tested yet as I have many troubles to convert the input file from LaTeX to plain TeX. Benchmarking will be done soon.
- It can be used only for an input file with tight paper size.
- Steps:
TEX -> DVI -> PDF -> EPS
.
- It runs faster than
batchA.bat
because no cropping with pdfcrop
. The drawback is you must specify the paper size tightly.
BatchE.bat
rem batchE.bat
rem echo off
latex -interaction=nonstopmode %1
dvips -R -t unknown -E %1 -o %1-temp.eps
epstool --copy --bbox %1-temp.eps %1.eps
epstopdf --hires %1.eps
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1-temp.eps
- It can be used for an input file with any paper size.
- Steps:
TEX -> DVI -> EPS -> bounding box correction -> PDF
.
- The file size of the resulting EPS is larger than that of one produced by each of the first 4 batch files (a,b,c,d).
BatchF.bat
rem batchF.bat
echo off
latex -interaction=nonstopmode %1
dvips -R -t unknown %1 -o %1-temp.ps
ps2eps %1-temp.ps
epstool --copy --bbox %1-temp.eps %1.eps
epstopdf --hires %1.eps
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1-temp.ps
del %1-temp.eps
- It can be used for an input file with any paper size.
- Steps:
TEX -> DVI -> PS -> EPS -> bounding box correction -> PDF
.
- The file size of the resulting EPS is larger than that of one produced by each of the first four batch files (a,b,c,d).
- I forgot the benchmark result when comparing
batchE.bat
and batchF.bat
.
Automate.bat
rem automate.bat
rem it takes a single character from {a,b,c,d,e,f}.
rem the options are case-insensitive.
rem for example: automate a
rem another example: automate F
echo off
for %%x in (*.tex) do batch%1.bat %%~nx
pause
If you have any problem, drop a comment.
Update in response to your misuse.
Each of {batchA.bat
,batchB.bat
,batchC.bat
,batchD.bat
,batchE.bat
,batchF.bat
} takes one input file name without extension. For example, if you want to use batchE.bat
for helloworld.tex
, then you must type batchE helloworld
and hit enter.
If you want to use batchE.bat
for a bunch of input files that exists in the same directory in which all batch files exist, then you type automate E
and hit enter.
Best Answer
One way would be to generate eps from graphviz with arbitrary simple labels and then insert LaTeX typeset labels using
psfrag
.