简体   繁体   English

r 中的滑动尺寸 slidy

[英]slide dimensions in r slidy

Using the default RStudio slidy html presentation template creates slides that have figures with fixed size (I believe 7 inches x 5 inches).使用默认的 RStudio slidy html 演示文稿模板创建的幻灯片具有固定大小的图形(我相信是 7 英寸 x 5 英寸)。 When viewing on a larger/higher resolution screen, that can leave a lot of empty space (zooming only changes the size of the text, not the figure):在更大/更高分辨率的屏幕上查看时,会留下很多空白空间(缩放只会改变文本的大小,不会改变图形的大小):

在此处输入图像描述

But adding knitr::opts_chunk$set(echo = FALSE, out.width = '100%') to an R chunk in order to auto-scale the figure size results in a figure that's too tall and requires scrolling to see all the content:但是将knitr::opts_chunk$set(echo = FALSE, out.width = '100%')添加到 R 块以自动缩放图形大小会导致图形太高并且需要滚动才能查看所有内容:

在此处输入图像描述

Using out.height='100%' instead of out.width='100%' seems to revert to the original size without changing the figure dimensions:使用out.height='100%'而不是out.width='100%'似乎可以在不更改图形尺寸的情况下恢复到原始大小:

在此处输入图像描述

Is there a better way to control slide dimensions and/or the size of content on html slides other than manually specifying the size of content in inches?除了以英寸为单位手动指定内容大小之外,是否有更好的方法来控制 html 幻灯片上的幻灯片尺寸和/或内容大小? When I look at example slides online, they all fill the screen very nicely ( eg ).当我在线查看示例幻灯片时,它们都很好地填满了屏幕(例如)。 How does one go about actually accomplishing that?一个 go 如何真正做到这一点? Or is the "solution" to just use PDF output?还是仅使用 PDF output 的“解决方案”?

For reference, here is the default slidy presentation code:作为参考,这里是默认的滑动演示代码:

---
title: "Untitled"
author: "Author"
date: "`r Sys.Date()`"
output: slidy_presentation
---

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

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Output

```{r cars, echo = TRUE}
summary(cars)
```

## Slide with Plot

```{r pressure}
plot(pressure)
```

You can define a knitr hook to enclose the figure in a div tag with class myfigure :您可以定义一个 knitr 钩子以将图形包含在带有 class myfigurediv标签中:

```{r setup, include=FALSE}
knitr::knit_hooks$set(myfigure = function(before, options, envir) {
  if(before) {
    "<div class='myfigure'>"
  } else {
    "</div>"
  }
})
```

Then, using CSS, define the height of the elements having the myfigure class in the vh unit (percentage of the viewport):然后,使用 CSS,在vh单元中定义具有myfigure class 的元素的高度(视口的百分比):

```{css}
.myfigure { 
  height: 75vh;
}
```

Now use this stuff as follows:现在使用这些东西如下:

```{r pressure, echo=FALSE, out.width="100%", out.height="100%", myfigure=TRUE}
plot(pressure)
```

Better, instead of using the same height for all elements having the myfigure class, you can define this hook which allows to set the height in the chunk options:更好的是,不是对具有myfigure class 的所有元素使用相同的高度,您可以定义这个钩子,它允许在块选项中设置高度:

```{r setup, include=FALSE}
knitr::knit_hooks$set(myfigure = function(before, options, envir) {
  if(before) {
    sprintf("<div class='myfigure' style='height:%svh'>", options$myheight)
  } else {
    "</div>"
  }
})
```

And use this hook as follows (remove the above CSS chunk):并按如下方式使用此钩子(删除上面的 CSS 块):

```{r pressure, echo=FALSE, out.width="100%", out.height="100%", myfigure=TRUE, myheight="75"}
plot(pressure)
```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM