[r] Plot size and resolution with R markdown, knitr, pandoc, beamer

Doesn't fit on the slide by default, doesn't even print by any other means.

Here's the .Rmd: Edit: it seems you have to use plot() in every chunk. Second plot now prints.

# Plot should show at high resolution

```{r echo=FALSE, comment = ""}
# load some data
require(plyr)
rbi <- ddply(baseball, .(year), summarise,  
  mean_rbi = mean(rbi, na.rm = TRUE))
```

```{r}
# plot
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Second attempt
```{r, fig.width = 2, fig.height = 2}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Third attempt
```{r, out.width = 2, out.height = 2}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Fourth attempt
```{r, out.width = '200px', out.height = '200px'}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Fifth attempt
```{r, out.width = '\\maxwidth'}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

Save that as test.Rmd Then compile to tex using beamer:

knit("test.Rmd")
system("pandoc -s -t beamer --slide-level 1 test.md -o test.tex")

Open test.tex in RStudio and click "Compile PDF".

I've read Yihui's documentation and hope I haven't missed something really obvious.

Edit new code incorporating Yihui's suggestions.

```{r setup, include=FALSE}
opts_chunk$set(dev = 'pdf')
```

# Plot should show at high resolution

```{r echo=FALSE, comment = ""}
# load some data
require(plyr)
rbi <- ddply(baseball, .(year), summarise,  
  mean_rbi = mean(rbi, na.rm = TRUE))
```

```{r}
# plot
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Second attempt
```{r, fig.width = 4, fig.height = 4}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

sessionInfo()

 R version 3.0.1 (16/05/2013)
Platform: x86_64-pc-linux-gnu (64-bit)

Local:
 [1] LC_CTYPE = en_US.UTF-8 LC_NUMERIC = C LC_TIME = C LC_COLLATE = C        
 [5] LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C           
 [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

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

other attached packages:
[1] plyr_1.8       markdown_0.6   knitr_1.2      rCharts_0.3.51 slidify_0.3.52

loaded via a namespace (and not attached):
 [1] RJSONIO_1.0-3   codetools_0.2-8 digest_0.6.3    evaluate_0.4.3  formatR_0.8    
 [6] grid_3.0.1      lattice_0.20-15 stringr_0.6.2   tools_3.0.1     whisker_0.3-2  
[11] yaml_2.1.7  

This question is related to r knitr pandoc beamer r-markdown

The answer is


Figure sizes are specified in inches and can be included as a global option of the document output format. For example:

---
title: "My Document"
output:
  html_document:
    fig_width: 6
    fig_height: 4
---

And the plot's size in the graphic device can be increased at the chunk level:

```{r, fig.width=14, fig.height=12}          #Expand the plot width to 14 inches

ggplot(aes(x=mycolumn1, y=mycolumn2)) +     #specify the x and y aesthetic
geom_line(size=2) +                         #makes the line thicker
theme_grey(base_size = 25)                  #increases the size of the font
```

You can also use the out.width and out.height arguments to directly define the size of the plot in the output file:

```{r, out.width="200px", out.height="200px"} #Expand the plot width to 200 pixels

ggplot(aes(x=mycolumn1, y=mycolumn2)) +     #specify the x and y aesthetic
geom_line(size=2) +                         #makes the line thicker
theme_grey(base_size = 25)                  #increases the size of the font
```

Examples related to r

How to get AIC from Conway–Maxwell-Poisson regression via COM-poisson package in R? R : how to simply repeat a command? session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium How to show code but hide output in RMarkdown? remove kernel on jupyter notebook Function to calculate R2 (R-squared) in R Center Plot title in ggplot2 R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph R multiple conditions in if statement What does "The following object is masked from 'package:xxx'" mean?

Examples related to knitr

How to show code but hide output in RMarkdown? R Markdown - changing font size and font type in html output Plot size and resolution with R markdown, knitr, pandoc, beamer How to set size for local image using knitr for markdown? Hiding the R code in Rmarkdown/knit and just showing the results R - Markdown avoiding package loading messages How to convert R Markdown to PDF?

Examples related to pandoc

How can I create a text box for a note in markdown? Plot size and resolution with R markdown, knitr, pandoc, beamer How to set size for local image using knitr for markdown? How to convert R Markdown to PDF?

Examples related to beamer

Plot size and resolution with R markdown, knitr, pandoc, beamer Beamer: How to show images as step-by-step images LaTeX beamer: way to change the bullet indentation?

Examples related to r-markdown

How to show code but hide output in RMarkdown? How to add new line in Markdown presentation? R Markdown - changing font size and font type in html output How to add \newpage in Rmarkdown in a smart way? Insert picture/table in R Markdown Centering image and text in R Markdown for a PDF report Plot size and resolution with R markdown, knitr, pandoc, beamer Hiding the R code in Rmarkdown/knit and just showing the results R - Markdown avoiding package loading messages How to convert R Markdown to PDF?