title: How to adjust figure size in pdf rendered directly from R script?
body: <p>I read from some where on SO that figure size for pdf rendered directly from a R script can be set with <code>knitr::opts_chunk</code>. I want to make a pdf from a R script with several figures and tried to adjust figure size with <code>opts_chunk</code>. However, it didn't work. Below is an short example.</p>
  
  <p>This is a script called <code>main.R</code>:</p>
  
  <pre><code>#' ---
  #' title: "test"
  #' output:
  #'     pdf_document
  #' ---
  
  #' ## draw a long figure, not a wide figure
  knitr::opts_chunk$set(fig.width = 3, fig.height = 5)
  plot(mtcars$mpg, mtcars$drat)
  </code></pre>
  
  <p>I tried to get desired pdf in rstudio with command ctrl + shift + K. A snapshot of the pdf I got looks like this:
  <a href="https://i.stack.imgur.com/bTota.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bTota.png" alt="enter image description here"></a></p>
  
  <p>although I wanted a 3x5 figure, this seems to be a 5x3 figure. How should I specify the figure width and height correctly in R script in order to get desired output?</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.3.1 (2016-06-21)
  Platform: x86_64-pc-linux-gnu (64-bit)
  Running under: Ubuntu 16.04.2 LTS
  
  locale:
   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
   [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
   [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  loaded via a namespace (and not attached):
   [1] backports_1.0.5 magrittr_1.5    rprojroot_1.2   htmltools_0.3.5 tools_3.3.1     yaml_2.1.14    
   [7] Rcpp_0.12.10    stringi_1.1.2   rmarkdown_1.3   knitr_1.15.1    stringr_1.1.0   digest_0.6.12  
  [13] evaluate_0.10  
  &gt; 
  &gt; windows.options()
  Error: could not find function "windows.options"
  </code></pre>