简体   繁体   中英

Creating gallery-like plots in HTML from R Markdown

I am working on a data analysis project in R. In the end I need to hand in an HTML document.

I created a couple of PCA biplots using the autoplot funciton, about like this:

autoplot(pca, data = expression, x = 1, y = 2)

#pca is a prcomp element and expression is a data frame

By now, they are plotted one below the other in the HTML document. Is there a function that allows me to click through the different plots? So that only the first plot is shown and by clicking on an arrow or something, the second plot is shown in the same place? Kind of like a gallery.

The way multiple plots from the same chunk are show in an R Markdown would be even better, so you can select one specific plot by clicking on a miniature version of it

I've been looking through the internet a lot and hoped to find something from the html widgets page, but couldn't find anything after all.

I would really appreciate your help on this. Thanks:)

EDIT : I am not sure whether I am allowed to hand in a shiny applet, so being able to do it solely in the HTML would be awesome

Right, I found a way to do it that works fine for me. I used the {.tabset} argument I found at this link:

https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html

## Results {.tabset}

### PC1-PC2 biplot

autoplot(pca, data = expression, x = 1, y = 2)

### PC1-PC3 biplot

autoplot(pca, data = expression, x = 1, y = 3)

## {-}

To use this, you have to create headers in your markdown using the # symbol. All headers that are one "level" below the one to which you added the {.tabset} argument (ie that have one more # symbol) will be the names of your tabs.

To close the tab section, you use the same number of # symbols you used in the header behind which you wrote the {.tabset} argument and write {-} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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