Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What I need is something like this:

enter image description here

The problem with this R package is that you can't export into pdf format to include in a LaTeX document. Any suggestions?

share|improve this question
    
This TeXample shows how to produce a map of India with TikZ. It may be of interest to you. –  Jubobs Mar 22 '13 at 21:00
    
I wonder if your question would be better in an R forum. Maybe try stackoverflow.com? –  Andy Clifton May 19 '13 at 20:47
    
The answer depends if your question is "how do I produce graphics from R in a format that tex will tolerate?", or "how do I produce this map in Latex?"... R will export to a variety of graphics formats, but the format depends a bit on the platform. If you are using a mac, you can print direct to PDF. If you use windows, you'll have to try another format. When I work across platforms, I use PNG; you can import it into LaTeX easily enough. –  Andy Clifton Jun 22 '13 at 23:03
add comment

1 Answer

You can’t export R to PDF directly (afaik), but you can export to TikZ, which is a drawing package for LaTeX. You use an R package called tikzDevice. From the tikzDevice project page:

The tikzDevice package provides a graphics output device for R that records plots in a LaTeX-friendly format. The device transforms plotting commands issued by R functions into LaTeX code blocks. When included in a paper typeset by LaTeX, these blocks are interpreted with the help of TikZ - a graphics package for TeX and friends written by Till Tantau. Using the tikzDevice, the text of R plots can contain LaTeX commands such as mathematical formula. The device also allows arbitrary LaTeX code to be inserted into the output stream.

On TeXample, there’s an example demonstrating the use of tikzDevice to plot a normal distribution and a linear model. That gives you the basic flavour, and then the package documentation goes into it in more detail.

Plotting your R graphs in TikZ means that the graph labels inherit the style of your LaTeX document (for example, if you’re using a different font), and you can embed arbitrary LaTeX in the labels. The TikZ it produces isn’t wonderfully pretty (imo), but it gets the job done, and it can be edited quickly in a pinch.

Normally I output my R code with tikzDevice to a subfolder of my working directory called figures (so a plot might be figures/geomap-global.tex) and then include it in my LaTeX document with \input{figures/geomap-global.tex}.

Just as an example, here’s a scatterplot made in R with tikzDevice:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.