0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rmarkdownを利用して、ggplotで書いたグラフ1枚1スライドのパワポを作りたい。

Posted at

Rmarkdownを利用して、forループ内ggplotで書いたグラフ1枚1スライドのパワポを作りたい。

R-wakalangで聞いたところ、良い回答を貰えたので備忘録的に貼っておく。
tnkkntさんありがとうございました。

##チャンクオプション {r setup, include = FALSE}
library(knitr)
knitr::opts_chunk$set(cache = FALSE, dev = "svg", dpi = 300)
library(tidyverse)
##チャンクオプション {r eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
for (i in 1:10){
    slide_title <- paste0("## 第", i, "節\n\n")
    cat(slide_title)
    dat <- rnorm(10, mean = i)
    df <- data.frame(id = 1:10, dat)
    p <- ggplot(df, aes(x = dat)) + geom_histogram()
    print(p)
    cat("\n\n")
}

results="asis"を使うことで、テキストを生の Markdown として出力することができる。生のMarkdownに改スライドを入れておけばループでスライドが切り替わる。
とてもcoolですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?