Rpresentation in Rstudio - Make image fill out the whole screen

后端 未结 5 1296
星月不相逢
星月不相逢 2020-12-23 11:36

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 sli

相关标签:
5条回答
  • 2020-12-23 12:15

    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)
    ```
    
    0 讨论(0)
  • 2020-12-23 12:19

    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"}
    
    
    0 讨论(0)
  • 2020-12-23 12:21

    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.

    0 讨论(0)
  • 2020-12-23 12:23

    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 讨论(0)
  • 2020-12-23 12:26

    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.

    0 讨论(0)
提交回复
热议问题