4

I have some figures generated by R too tall to fit on the page. I want to include these figures but scale down the figure according to a height restriction.

<<fig=TRUE,out.height='0.7\\textheight'>>=

Unfortunately, this squishes the plot vertically.

Inspecting the generated latex code reveals that the problem lies with the fact that width=\maxwidth is set automatically:

\begin{knitrout}\footnotesize
...
\includegraphics[width=\maxwidth,height=0.7\textheight]{figures/view_unnamed-chunk-10} 
\end{knitrout}

How can I keep the width=\maxwidth specification from appearing in the \includegraphics statement without setting the out.width argument in <<>>= explicitly? In this example, fig.width==fig.height so I could additionally set out.width='0.7\\textheight' (and adjust accordingly for the any aspect ratio), but I would like know for the more general case.

Passing keepaspectratio=TRUE in <<>>= is ignored, so that doesn't seem to be an option.

hatmatrix
  • 42,883
  • 45
  • 137
  • 231
  • I can't remember where I saw it, but I found out that it's better to set `fig.show = "hide"` and then use `\includegraphics` later with the path to the figure being `figures/chunk-name-1`, where you replace `chunk-name` with the name of the chunk and `1` with the number of the plot you want to plot. – ZNK Jul 23 '15 at 04:31

1 Answers1

4

I had a similar problem. I found out that you can use the out.extra parameter to provide keepaspectratio option.

This is how it may look like:

<<out.height='0.7\\textheight',out.extra='keepaspectratio'>>=

The LaTex code then will look something like this:

\includegraphics[width=\maxwidth,height=0.7\textheight,keepaspectratio]{figure/unnamed-chunk-1-1} 
karlos
  • 873
  • 2
  • 10
  • 21