knitr:如何在图中设置keepaspectratio

时间:2014-03-11 09:49:52

标签: r knitr

我有一些由R生成的数字太高而无法放在页面上。我想要包括这些数字,但要根据高度限制缩小数字。

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

不幸的是,这会垂直地收集情节。

检查生成的乳胶代码可以发现问题在于width=\maxwidth是自动设置的:

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

如果没有在width=\maxwidth中明确设置\includegraphics参数,如何使out.width规范不会出现在<<>>=语句中?在此示例中,fig.width==fig.height因此我可以另外设置out.width='0.7\\textheight'(并根据任何宽高比进行相应调整),但我想知道更一般的情况。

keepaspectratio=TRUE中传递<<>>=会被忽略,因此这似乎不是一个选项。

1 个答案:

答案 0 :(得分:4)

我有类似的问题。我发现您可以使用out.extra参数提供keepaspectratio选项。

这就是它的样子:

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

然后,LaTex代码将如下所示:

\includegraphics[width=\maxwidth,height=0.7\textheight,keepaspectratio]{figure/unnamed-chunk-1-1}