使用gganimate在iSlides演示文稿的knitr标记中显示动画打印:根目录
我想用knitr将ggplot和gganimate生成的绘图嵌入到幻灯片中。当数据和.Rmd文件位于同一文件夹中时,我可以生成动画 下面是一个可复制的动画示例使用gganimate在iSlides演示文稿的knitr标记中显示动画打印:根目录,r,ggplot2,r-markdown,knitr,gganimate,R,Ggplot2,R Markdown,Knitr,Gganimate,我想用knitr将ggplot和gganimate生成的绘图嵌入到幻灯片中。当数据和.Rmd文件位于同一文件夹中时,我可以生成动画 下面是一个可复制的动画示例 ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE) library(ggplot2) library(gganimate) library(gapminder) ``` ## Static plot create ```{r, } ranim <- ggp
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)
library(gganimate)
library(gapminder)
```
## Static plot create
```{r, }
ranim <- ggplot(gapminder, aes(x = gdpPercap,y=lifeExp,
size = pop,
colour = country)) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
```
## Static plot
```{r, }
ranim
```
## Build animate
```{r, }
ranim2 <- ranim +
transition_time(year) +
labs(title = "Year: {frame_time}")
```
## View animate
```{r, }
animate(ranim2)
```
My.Rmd文件保存在Project1文件夹中。代码如下,编译时生成一张空白幻灯片。通过从.Rmd手动运行代码块,我可以在查看器中生成动画文件。但是当html编译时,它是空白的
是否有建议的设置来组织项目子文件夹中的本地数据,并从主项目1文件夹中保存的.Rmd生成降价幻灯片
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_knit$set(root.dir = './Data')
library(ggplot2)
library(gganimate)
library(gapminder)
```
## slide 1
```{r, }
datain <- read.csv("table1.csv")
panim <- ggplot(datain, aes(x, y, frame = year)) + geom_point()
```
## Static plot view
```{r, }
panim
```
## Static plot add animate
```{r, }
panim2 <- panim + transition_time(year) +
labs(title = "Year: {frame_time}")
```
## Activate animate
```{r, }
animate(panim2)
```
`{r设置,include=FALSE}
knitr::opts_chunk$set(echo=FALSE)
knitr::opts_knit$set(root.dir='./Data')
图书馆(GG2)
库(gganimate)
图书馆(gapminder)
```
##幻灯片1
```{r,}
datain不确定您的问题到底是什么,或者您使用的幻灯片输出样式,但是这段代码对我来说很好(我得到一张带有静态图像的幻灯片和一张带有动画的幻灯片)
---
标题:“演示文稿”
作者:“我”
日期:“2019年2月20日”
输出:ioslides\u演示文稿
---
##幻灯片1
```{r,warning=F}
library(ggplot2)
library(gganimate)
library(gapminder)
```
##幻灯片2
```{r}
ranim <- ggplot(gapminder, aes(x = gdpPercap,y=lifeExp,
size = pop,
colour = country)) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
ranim
ranim2 <- ranim +
transition_time(year) +
labs(title = "Year: {frame_time}")
animate(ranim2)
```
##幻灯片4
```{r}
ranim <- ggplot(gapminder, aes(x = gdpPercap,y=lifeExp,
size = pop,
colour = country)) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
ranim
ranim2 <- ranim +
transition_time(year) +
labs(title = "Year: {frame_time}")
animate(ranim2)
```谢谢你,请参阅关于目录的修订问题。