r图形高度/宽度的编织块选项不起作用 [英] r knitr chunk options for figure height / width are not working

查看:91
本文介绍了r图形高度/宽度的编织块选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在R中使用knitr来生成.Rnw格式的报告.在我的报告中,我经常放很多图,并使用块优化来操纵它们的大小,例如:

I used to use knitr in R to produce reports from the .Rnw format. In my reports I often put a plenty of plots and manipulated their size with the use of chunk optios, e.g.:

\begin{figure}[h!]
\centering
<<fig.width=6, fig.height=4, out.width='.89\\linewidth'>>=

plot(mtcars)

@
\caption{}
\end{figure}

几个月前.然后,我移到另一个环境,重新安装了R,这些选项似乎不再起作用-图的大小在PDF输出上保持不变

It was few months ago. Then I moved to another environment, reinstalled R and these options seem no longer work - the plot size stays unchanged on the PDF output!

以下是有关任何选项设置的所有代码行.我期待任何建议,我做错了什么.

Here comes all the lines of code regarding any option settings. I am looking forward any suggestions what am I doing wrong.

<< >>=
library(knitr)
knitr::opts_chunk$set(echo=F, eval=T, message = F, warning=F, cache = F, fig=TRUE)
@

\begin{figure}[h!]
\centering
<<fig.width=10, fig.height=3, out.width='.89\\linewidth', fig=TRUE, echo=F>>=
plot(mtcars)
@
\caption{mtcars plot}
\end{figure}

当我使用<<fig.width=10, fig.height=3, fig=TRUE, echo=F>>=时,会出现完全相同的结果.

Exactly the same result appears when I use <<fig.width=10, fig.height=3, fig=TRUE, echo=F>>=.

会话信息

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8      
 [2] LC_NUMERIC=C              
 [3] LC_TIME=pl_PL.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=pl_PL.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=pl_PL.UTF-8      
 [8] LC_NAME=C                 
 [9] LC_ADDRESS=C              
[10] LC_TELEPHONE=C            
[11] LC_MEASUREMENT=pl_PL.UTF-8
[12] LC_IDENTIFICATION=C       

attached base packages:
[1] splines   stats4    stats     graphics  grDevices
[6] utils     datasets  methods   base     

other attached packages:
 [1] bootstrap_2014.4     dplyr_0.3.0.9000    
 [3] het.test_0.1         vars_1.5-2          
 [5] lmtest_0.9-33        urca_1.2-8          
 [7] strucchange_1.5-0    sandwich_2.3-2      
 [9] zoo_1.7-11           MASS_7.3-34         
[11] VGAM_0.9-6           ggplot2_1.0.0       
[13] manipulate_0.98.1078

loaded via a namespace (and not attached):
 [1] assertthat_0.1   colorspace_1.2-4 DBI_0.3.1       
 [4] digest_0.6.4     evaluate_0.5.5   formatR_1.0     
 [7] grid_3.1.1       gtable_0.1.2     htmltools_0.2.6 
[10] knitr_1.7        labeling_0.3     lattice_0.20-29 
[13] lazyeval_0.1.9   magrittr_1.0.1   munsell_0.4.2   
[16] parallel_3.1.1   plyr_1.8.1       proto_0.3-10    
[19] Rcpp_0.11.3      reshape2_1.4     rmarkdown_0.3.9 
[22] scales_0.2.4     stringr_0.6.2    tools_3.1.1     
[25] yaml_2.1.13    

PDF输出截图(大小不变)

推荐答案

我很确定您使用的是Sweave而不是 knitr .如果您使用的是RStudio(您没有说出来,但我想是这样),则需要将全局选项(或项目选项)更改为 knitr :

I'm pretty sure you were using Sweave instead of knitr. If you were using RStudio (you did not say it but I guess so), you need to change the global option (or project option) to knitr:

这篇关于r图形高度/宽度的编织块选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆