Pregunta

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.

¿Fue útil?

Solución

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} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top