Issue
I've been trawling for a while to solve this one. Is there a way I can lengthen .tabset
panels in an rmd HTML output, or ideally have them a dynamic length in the HTML output to stop plots getting squashed?
RePrEx:
---
title: "test"
output: html_document
date: "2022-07-27"
---
```{r}
library(ggplot2)
library(patchwork)
gg0 <- list()
p1 <- ggplot(mtcars, aes(mpg, hp)) + geom_point()
p2 <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
p3 <- ggplot(mtcars, aes(mpg, drat)) + geom_point()
gg0[[1]] <- p1/p1/p1/p1
gg0[[2]] <- p1/p1/p1/p1/p1/p1
gg0[[3]] <- p1/p1/p1/p1/p1/p1/p1/p1/p1
headings <- c('hp','disp','drat')
```
#### Heading {.tabset}
```{r, results='asis', echo = FALSE}
for (i in 1:length(gg0)) {
cat("##### ",headings[i],"\n")
print(gg0[[i]])
cat('\n\n')
}
```
Example shamelessly borrowed and adapted from here. Figures look quite small when knit, especially complex plots.
Thanks!
P.S. I'm not that familiar with CSS if it needs to be done that way
Solution
In RMarkdown we can control the size of plots using fig.dim
fig. width
or fig.height
(see here).
In your case setting fig.height
to 10
yields good results:
---
title: "test"
output: html_document
date: "2022-07-27"
---
```{r}
library(ggplot2)
library(patchwork)
gg0 <- list()
p1 <- ggplot(mtcars, aes(mpg, hp)) + geom_point()
p2 <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
p3 <- ggplot(mtcars, aes(mpg, drat)) + geom_point()
gg0[[1]] <- p1/p1/p1/p1
gg0[[2]] <- p1/p1/p1/p1/p1/p1
gg0[[3]] <- p1/p1/p1/p1/p1/p1/p1/p1/p1
headings <- c('hp','disp','drat')
```
#### Heading {.tabset}
```{r, results='asis', echo = FALSE, fig.height = 10}
for (i in 1:length(gg0)) {
cat("##### ",headings[i],"\n")
print(gg0[[i]])
cat('\n\n')
}
```
Answered By - TimTeaFan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.