Installation
rmarkdown
tinytex
pandoc
預(yù)先要安裝好以上幾個包。
R Markdown生成PowerPoint原理
使用示例
講解視頻 https://www.youtube.com/watch?v=uiA3znJb4KM
具體參數(shù)和步驟: 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設(shè)置
2、通過R code讀入
注意:R code要設(shè)置不打印出來醇蝴,不然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
字體設(shè)置
插入圖片
1想罕、已知圖片名悠栓、路徑,直接插入
![image description](imageName.png){50%width}
## fig.align設(shè)置fig位置按价,fig.cap設(shè)置fig的說明
knitr::include_graphics('images/hex-rmarkdown.png')
2惭适、文件路徑或名稱不明確,帶入變量插入
如果需要對文件名進行匹配顯示楼镐,或者代碼匹配未知個同樣文件名規(guī)律的圖片癞志,放置在PPT中,可以使用cat
進行打印操作框产,示例如下:
(1)文件路徑為變量凄杯,使用cat
和paste0
結(jié)合
cat(paste0("[圖片上傳失敗...(image-a760c0-1634006991616)]")))
(2)根據(jù)文件數(shù)量生成對應(yīng)個數(shù)的幻燈片頁面,和與內(nèi)容對應(yīng)的標題
# 1秉宿、根據(jù)文件名規(guī)律獲取文件列表
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: 注釋內(nèi)容
隔崎,PPT中文字會出現(xiàn)在表的下方。例如:
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 |
插入dataframe
knitr::kable(stat,align = 'c', format = "markdown")
分列
這個功能在ppt排版時非常常用
:::::::::::::: {.columns}
::: {.column}
contents...
:::
::: {.column}
contents...
:::
::::::::::::::
演講者筆記
使用ppt模板
在Rmarkdown文件開頭yml中設(shè)置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")