r - 在 Rmarkdown 中生成动态 .tabset
问题描述
我想创建 3 个 .tabsets,每个级别的 Iris 数据集上的 Species 一个(示例)。在每个 .tabset 上,需要 3 个或更多选项卡。每个选项卡都有你自己的情节。
我写了这段代码:
```{r echo=FALSE, results='asis'}
library(tidyverse)
for(especies in levels(iris$Species)){
cat('\n#', especies, '{.tabset}', '\n')
cat('\n##', 'Petal Lengh x Sepal Length', '\n')
iris %>%
filter(
Species == especies
) %>%
ggplot(
aes(
x = Sepal.Length,
y = Petal.Length
)
) +
geom_point() -> p
print(p)
cat('\n')
cat('\n##', 'Sepal Length', '\n')
iris %>%
filter(
Species == especies
) %>%
ggplot(
aes(
x = Sepal.Length
)
) +
geom_histogram() -> p
print(p)
cat('\n')
cat('\n##', 'Petal Length', '\n')
iris %>%
filter(
Species == especies
) %>%
ggplot(
aes(
x = Petal.Length
)
) +
geom_histogram() -> p
print(p)
}
```
我不知道为什么它不起作用。有任何想法吗?
提前致谢!
堆栈不断要求我提供更多详细信息以发布问题,所以我必须再写一些才能被允许发布。
解决方案
获得预期结果的两件事:
1){r, results = "asis"}
作为块插入
2)cat('\n')
在最后一次print
调用之后添加
推荐阅读
- pandas - 如何防止seaborn在Timeseries Plot的xtick标签中跳过年份
- php - CURL 的 SMS API 问题
- fortran - openmp 和共享与私有
- java - 是否可以通过导入语句(Mockito)注入模拟?
- javascript - Webpack 找不到 Typescript 类型解析所需的导入。如何解决这个问题?
- swift - AVCaptureAudioDataOutput 没有调用 AVCaptureAudioDataOutputSampleBufferDelegate.captureOutput
- python - 导入 csv 文件并转换为具有特殊格式的数据框
- matlab - matlab符号数组排序问题与 equationsToMatrix 函数
- linux-kernel - 在不使用 IPC 的情况下从另一个 init 脚本向 Python 守护程序脚本发送消息
- javascript - 如何修复“错误:找不到模块'@keyv/sqlite'”错误?