31

Making an Rpresentation in Rstudio with knitr I have a slide with just one picture, which I want to fill out the whole screen/slide. How do I do that?

The second slide of the following .Rpres-document is set to 2000x2000 pixels but it still only fills a small area of the screen:

first slide
======


Slide with plot which I want to fill the whole screen
========================================================
title: false
```{r, echo=FALSE,out.height="2000px",out.width="2000px"}
plot(cars)
```

This is what I mean when I write that the picture does not "fill the whole screen", the red lines are drawn at parts of the screen which are not filled by the plot.

enter image description here

update november 2016

Choosing "HTML Slidy" when creating a new presentation in Rstudio Version 1.0.44, gives me easier control of the size. The following is close to what i wanted on a full HD resolution, and very simple to do:

---
title: "Untitled"
output: slidy_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## 

```{r pressure, fig.height=10, fig.width=19}
plot(pressure)
```
Rasmus Larsen
  • 5,721
  • 8
  • 47
  • 79
  • The problem is not the size of the image, but the border rpresentation adds around the slides (check it out using something like chrome's inspector). I had a quick play with trying adjusting the slide size (here http://www.rstudio.com/ide/docs/presentations/displaying_and_distributing_presentations) but without much luck. You can probably do it using custom css (http://www.rstudio.com/ide/docs/presentations/customizing_fonts_and_appearance), but afaict, there doesn't seem to be a way to get the generated image to be larger than 504px high... – Oliver Matthews May 15 '14 at 16:15
  • I remember there is a restriction of the image width in CSS (`max-width`), and you may need to try something like the chunk option `out.extra='style="max-width: 2000px;"'`. – Yihui Xie May 16 '14 at 06:16
  • If you're using the "original" (i.e. reveal.js) .Rpres format, then you can try to incorporate the reveal.js "fullscreen" plugin - https://github.com/regisb/reveal.js-fullscreen-img - but it will require post-processing since I've not found a way to influence the production of "
    " tag areas from within RStudio. If you're using ioslides output, I'm not sure how to influence fullscreen image display.
    – hrbrmstr May 18 '14 at 15:37

5 Answers5

43

Here's the way to set the overall presentation size: http://www.rstudio.com/ide/docs/presentations/displaying_and_distributing_presentations The default is quite small: 960 * 700.

The interaction between the figure sizes, output sizes, and presentation sizes is tricky and I'm not an expert, but this seems to work ok. After some messing around, this looked alright:

first slide
======
width: 1920
height: 1080

Slide with plot which I want to fill the whole screen
========================================================
title: false
```{r myplot,echo=FALSE,fig.width=8,fig.height=4.5,dpi=300,out.width="1920px",out.height="1080px"}
plot(cars)
```
Verena Haunschmid
  • 1,252
  • 15
  • 40
oropendola
  • 1,081
  • 7
  • 8
1

You can find your screen size and use that to set the plot size using grDevices a = dev.size("px")

and then you can use that in your code.

Thanushan
  • 532
  • 2
  • 8
  • 4
    Finding the screen size is not the problem. The problem is that the plot does not obey the size I try to set. My screen is 1920x1080 and the plot is set to 2000x2000pixels and still only fills a small part of the screen. – Rasmus Larsen May 13 '14 at 12:44
  • In my case the value I get from dev.size seems to be the current value of dev (427, 230), what is not the maximum size of the device. The idea is good and clearly the way to go (finding the device size and use it) but seems something else is missing for it to work as expected. – Picarus Mar 07 '16 at 00:34
1

knitr version: 1.16

RStudio version: 1.0.143

problem description: when knitr parses the R code, even if you set a custom css page width, the output an html file has a constant max-width: 940px;

knitr output :

max-width: 940px;

My css setting file

max-width: 2000px;

min-width: 700px;

knitr does recognise the custom css file, but it does not create an output according to my css settings. I know this because When I deliberately misspell the css file, knitr produces an error during output.

The solution that worked for me was to go to the file created by knitr and change by hand the max-width: 2000px; min-width: 700px;

Better solution would be of course to find the root of the problem in the knitr /pandoc program

0

Considering Andy's response, I restrained my output to 940px wide and obtained good results for both the RStudio fullscreen presentation and "View in Browser"

Adding to my setup block:

library(knitr)
opts_chunk$set(fig.width=8, fig.height=4.5, dpi=300, out.width="940px", out.height="529px")

If you use something like 1920 wide you will have issues when exporting to html or viewing in browser.

Mike
  • 384
  • 3
  • 9
0

If you're using reveal.js in Rmarkdown, applying the {data-background="my_img.png"} argument to a new slide allows you to use a newly generated plot as the image background for that slide, which fills out the entire device area without needing to modify any device output specs.

R plots are saved in the my_pres_files/figure-revealjs/ folder in your local dir. Attributing a name to the code chunk for the plot in your Rmd file will give the plot png file that name in this dir. E.g.

```{r, myplot} 
# r code to generate plot
# name the code chunk to attribute a name to the image file of the plot in your local dir
```

This will give you the following path:

"my_pres/my_pres_files/figure-revealjs/myplot-1.png"

Then use this path in the `data-background = "my_img.png" argument.

<!-- new revealjs slide -->

# {data-background="my_pres/my_pres_files/figure-revealjs/myplot-1.png"}