我有一些 R 生成的图形太高,无法在页面上显示。我想包含这些数字,但根据高度限制缩小数字。
<<fig=TRUE,out.height='0.7\\textheight'>>=
不幸的是,这会垂直挤压绘图。
检查生成的 latex 代码表明问题在于 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
在<<>>=
被忽略,所以这似乎不是一个选择。
最佳答案
我也遇到了类似的问题。我发现您可以使用 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}
关于r - knitr:如何在图中设置 keepaspectratio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22322008/