Installation
rmarkdown
tinytex
pandoc
预先要安装好以上几个包。
R Markdown生成PowerPoint原理
image.png使用示例
讲解视频 https://www.youtube.com/watch?v=uiA3znJb4KM
具体参数和步骤: https://support.rstudio.com/hc/en-us/articles/360004672913-Rendering-PowerPoint-Presentations-with-the-RStudio-IDE
Rmarkdown生成PPT:https://bookdown.org/yihui/rmarkdown/powerpoint-presentation.html
github示例:https://github.com/sol-eng/powerpoint
传参
1、通过params设置
image.png2、通过R code读入
注意:R code要设置不打印出来,不然code会显示在ppt上面。
config=yaml.load_file("config.yml")
species = config$species ##human or mouse
sample <- config$sample
rawname <- config$rawname
cellrangerdir <- config$dataDir
outdir <- config$analysisDir
字体设置
image.png插入图片
1、已知图片名、路径,直接插入
![image description](imageName.png){50%width}
## fig.align设置fig位置,fig.cap设置fig的说明
knitr::include_graphics('images/hex-rmarkdown.png')
2、文件路径或名称不明确,带入变量插入
如果需要对文件名进行匹配显示,或者代码匹配未知个同样文件名规律的图片,放置在PPT中,可以使用cat
进行打印操作,示例如下:
(1)文件路径为变量,使用cat
和paste0
结合
cat(paste0("[图片上传失败...(image-a760c0-1634006991616)]")))
(2)根据文件数量生成对应个数的幻灯片页面,和与内容对应的标题
# 1、根据文件名规律获取文件列表
img_list <- list.files( path = 'images', pattern = '*.png$', full.names=T, recursive=FALSE)
img_list <- img_list[grep("top8",img_list)]
# 2、依次生成幻灯片,每张放置两张图片,注意每页的标题,以及换行
for (n in 1:length(img_list)){
img1 <- paste0("index_files/figure-html/top8Markers.DimPlot-",n,".png")
img2 <- paste0("index_files/figure-html/top8Markers.DimPlot-",n+1,".png")
if (file.exists(img2)){
cat(paste0("## Cluster-specific genes", " (Top 8, Cluster ",n-1,",",n,")", "\n\n" ,
":::::::::::::: {.columns}", "\n", "::: {.column}","\n\n",
"[图片上传失败...(image-a2ae3a-1634006991616)]\n\n",
":::\n","::: {.column}","\n\n",
"[图片上传失败...(image-aa7455-1634006991616)]\n\n",
":::\n","::::::::::::::\n")
)
}else{
cat(paste0("## Cluster-specific genes", " (Top 8, Cluster ",n,")", "\n\n" ,
"[图片上传失败...(image-decf88-1634006991616)]
)
}
n <- n+2
}
cat(" \n")
打印出来是这样的:
## Cluster-specific genes (Top 8, Cluster 0,1)
:::::::::::::: {.columns}
::: {.column}
![](index_files/figure-html/top8Markers.DimPlot-1.jpeg)
:::
::: {.column}
![](index_files/figure-html/top8Markers.DimPlot-2.jpeg)
:::
::::::::::::::
## Cluster-specific genes (Top 8, Cluster 2,3)
:::::::::::::: {.columns}
::: {.column}
![](index_files/figure-html/top8Markers.DimPlot-3.jpeg)
:::
::: {.column}
![](index_files/figure-html/top8Markers.DimPlot-4.jpeg)
:::
::::::::::::::
插入表格
写法跟markdown一样,这里不再赘述。
manufacturer displ hwy class
------------- ------ ----- ---------
audi 1.8 29 compact
chevrolet 5.3 20 suv
dodge 2.4 24 minivan
Table: Simple table syntax and caption.
表的注释方法为 Table: 注释内容
,PPT中文字会出现在表的下方。例如:
Table: Gene expression visualization of widely occurring cell type markers. The following cell type markers are plotted.
| Gene | Common cell type |
|:-: | :-:
| EPCAM | Epithelial |
| CD3D | T cell |
| CD14 | Monocyte |
| CD68 | Macrophage |
| B cells | CD19 |
| PECAM1 | Endothelial |
| COL1A2 | Fibroblast |
| NCAM1 | NK |
| MZBI |Plasma |
| TPSAB1 | Mast |
image.png
插入dataframe
knitr::kable(stat,align = 'c', format = "markdown")
分列
这个功能在ppt排版时非常常用
:::::::::::::: {.columns}
::: {.column}
contents...
:::
::: {.column}
contents...
:::
::::::::::::::
image.png
演讲者笔记
image.png使用ppt模板
在Rmarkdown文件开头yml中设置output格式为powerpoint_presentation,reference_doc
给到你想使用的模板文件。
---
title: "Visium Standard Analysis Report"
date: "`r Sys.Date()`"
output:
powerpoint_presentation:
df_print: kable
slide_level: 2
reference_doc: template.pptx
---
生成PPT
R代码
rmarkdown::render("in.Rmd", output_format = "powerpoint_presentation")
网友评论