Skip to navigation

Using the LaTeX landscape package for a plot/ figure in Sweave

I’ve started using Sweave and immediately ran into a problem. I had a wide figure to include (actually, a plot that combined several plots in R using the layout command). I had used the lscape package in LaTeX and the corresponding landscape environment for that page, and before, it worked fine, but with Sweave, the figure got chopped off as if somehow LaTex was cropping it to the portrait-oriented “width”, i.e. the narrower side of the page. Turns out I had to follow my own advice and run dvips followed by ps2pdf instead of dvipdfm.

Since typing in all those commands including the now necessary Sweave gets quite tedious, I created a little shell script sweavetex:

#!/bin/bash

R CMD Sweave "$1".Rnw  || exit 1
latex "$1".tex || exit 1
dvips "$1".dvi || exit 1
ps2pdf -dAutoRotatePages=/None "$1".ps || exit 1

Comments are closed.