6
最近xaringanを使い始めました。本当にきれいです。素晴らしいパッケージのおかげでYihui。私が疑問に思っていた1つの質問は、forループにプロットされたプロットを含むスライドをプログラムで生成することが可能なのでしょうか?プログラムでRを使ってxaringanとpllyでスライドを生成
```{r, message=FALSE, warning=FALSE, results='asis'}
for (p in ggplot_list) {
cat("\n\n---\n")
print(p)
}
```
これは完璧に動作します:私はggplot_listがggplotsのリストである。このようなggplotsのスライドを、生成することができます知っています。
ggplotly(ggplot_list[[1]])
を呼び出すことで、プロットプロットを個別に含めることもできますが、これも完全に機能します。
しかし、私は2つの組み合わせがうまくいかないように思えます。次のようにすると、空のスライドが生成されます。
```{r, message=FALSE, warning=FALSE, results='asis'}
for (p in ggplot_list) {
cat("\n\n---\n")
ggplotly(p)
}
```
更新:ここでは、私がこれまで試したことの最小限の例を示します。
---
title: "xaringan + plotly + loop?"
subtitle: "Does it work?"
author: "Fenfen Kan"
date: "2017/13/32"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
# Several boring ggplots
```{r, message=FALSE, warning=FALSE}
library(ggplot2)
library(plotly)
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point(aes(color=Species))
p2 <- ggplot(iris, aes(Petal.Length, Petal.Width)) +
geom_point(aes(color=Species))
p3 <- ggplot(iris, aes(Sepal.Length, Petal.Length)) +
geom_point(aes(color=Species))
ggplot_list <- list(p1, p2, p3)
```
---
# Invididual plotly works
```{r}
ggplotly(p1)
```
---
# ggplot slides in loop also works
```{r, message=FALSE, warning=FALSE, results='asis'}
for (p in ggplot_list) {
cat("\n\n---\n")
print(p)
}
```
---
# plotly in loop doesn't work
```{r, message=FALSE, warning=FALSE, results='asis'}
for (p in ggplot_list) {
cat("\n\n---\n")
ggplotly(p)
}
```
# print(ggplotly(p)) in loop doesn't work either
```{r, message=FALSE, warning=FALSE, results='asis'}
for (p in ggplot_list) {
cat("\n\n---\n")
print(ggplotly(p))
}
```
あなたは 'print(ggplotly(p))'を試しましたか? –
ええ、それは私にとってもうまくいきません。これを最小限の例に追加します。 –