r - 缩放直接在 Xaringan 中渲染的 ggplot
问题描述
我在我的 Rmarkdown 文件中制作了以下图,并使用 Xaringan 渲染它。
---
title: "myTitle"
output:
xaringan::moon_reader:
css: ["default", "kunoichi", "ninjutsu", "metropolis-fonts"]
lib_dir: libs
chakra: libs/remark-latest.min.js
seal: false
nature:
countIncrementalSlides: false
ratio: '16:9'
---
# Two pretty gaussians
## and a few vertical lines
```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(cowplot)
ggplot(data = data.frame(x = c(-3, 3)), aes(x)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 1, sd = 1)) +
stat_function(fun = dnorm, n = 101, args = list(mean = -1, sd = 1)) +
geom_vline(xintercept = 0, colour="black", linetype = "solid") +
geom_vline(xintercept = c(-1.5,1.5), colour="black", linetype = "longdash") +
ylab("Density") + xlab("\'Internal Signal\'") +
scale_y_continuous(breaks = NULL)
```
这导致以下演示文稿。我只想使绘图更小,而无需将其保存为图像的间接步骤,然后调用它并对其进行缩放。
解决方案
使用out.width
或out.height
工作,同时保持纵横比。一起使用它们可以让您改变纵横比。使用fig.width
or fig.height
,正如@RichardTelford 所建议的那样,也可以使用,但不能保持纵横比。不过,您可以同时使用两者来获得正确的纵横比。
底线:如果我只是想缩小图像,我会使用out.width
or out.height
。
---
title: "myTitle"
output:
xaringan::moon_reader:
css: ["default", "kunoichi", "ninjutsu", "metropolis-fonts"]
lib_dir: libs
chakra: libs/remark-latest.min.js
seal: false
nature:
countIncrementalSlides: false
ratio: '16:9'
---
# Two pretty gaussians
## and a few vertical lines
```{r, echo=FALSE, message=FALSE, warning=FALSE, out.width = '200px'}
library(cowplot)
ggplot(data = data.frame(x = c(-3, 3)), aes(x)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 1, sd = 1)) +
stat_function(fun = dnorm, n = 101, args = list(mean = -1, sd = 1)) +
geom_vline(xintercept = 0, colour="black", linetype = "solid") +
geom_vline(xintercept = c(-1.5,1.5), colour="black", linetype = "longdash") +
ylab("Density") + xlab("\'Internal Signal\'") +
scale_y_continuous(breaks = NULL)
```
推荐阅读
- django - 如果它的 id 对其他表不可用并且在某些条件下过滤所有对象形式 django modal
- iot - IOT Central - 用于生产的真实设备
- android - TrueSDK.getInstance().getUserProfile(),这个方法的参数是什么使用例子
- ios - UIScrollView with dynamically sized content
- python - 数据集将多个相关记录转换为单个记录
- ios - Picker 不会从 CoreData (SwiftUI) 中选择值
- python - Configparser 不打开文件对象
- c - 分段故障信号 11
- ios - 是否可以使用 nativescript 创建照片清洁器应用程序?
- javascript - 为什么我的“重复字符串”代码不起作用?|| 黑客等级 || JavaScript