用rmarkdown定制你的數(shù)據(jù)分析報(bào)告
生物信息學(xué)習(xí)的正確姿勢(shì)
NGS系列文章包括NGS基礎(chǔ)、在線繪圖、轉(zhuǎn)錄組分析?(Nature重磅綜述|關(guān)于RNA-seq你想知道的全在這)、ChIP-seq分析?(ChIP-seq基本分析流程)、單細(xì)胞測(cè)序分析?(重磅綜述:三萬字長(zhǎng)文讀懂單細(xì)胞RNA測(cè)序分析的最佳實(shí)踐教程)、DNA甲基化分析、重測(cè)序分析、GEO數(shù)據(jù)挖掘(典型醫(yī)學(xué)設(shè)計(jì)實(shí)驗(yàn)GEO數(shù)據(jù)分析 (step-by-step))、批次效應(yīng)處理等內(nèi)容。
1、rmarkdown簡(jiǎn)介
markdown是一種輕量級(jí)標(biāo)記語言,它允許使用者可以通過簡(jiǎn)單的文本格式 編寫文檔,并且轉(zhuǎn)換成html文檔。markdown因?yàn)檎Z法簡(jiǎn)單、上手容易,現(xiàn)在也越來越多的被文檔編輯人員使用。有很多可以支持markdown編輯的應(yīng)用軟件,例如Mou、MarkdownEditor、Haroopad、Typora等,通過這些工具可以便捷的完成markdown文字錄入,并且支持導(dǎo)出PDF、HTML等格式。?
2、rmarkdown的輸出展示
2.1新建一個(gè)markdown項(xiàng)目


eval
eval控制了代碼塊是否執(zhí)行。若設(shè)定為eval=TRUE,則markdown會(huì)執(zhí)行代碼塊里的代碼;若eval=FALSE,則markdown不會(huì)執(zhí)行代碼。?echo
echo參數(shù)控制了markdown是否顯示代碼塊。若echo=TRUE,則表示代碼塊顯示在markdown文檔顯示代碼塊;反之,代碼塊不出現(xiàn)在輸出結(jié)果中。?collapse
collapse設(shè)置為TRUE或者FALSE.用來控制文本輸出結(jié)果是否和代碼塊混在一起。?fig.show :設(shè)置了圖片輸出方式? fig.show=‘a(chǎn)sis’:表示plot在產(chǎn)生他們的代碼后面 fig.show=‘hold’:所有代碼產(chǎn)生的圖片都放在一個(gè)完整的代碼塊之后 fig.show=‘a(chǎn)nimate’:表示將所有生成的圖片合成一個(gè)動(dòng)畫圖片 fig.show=‘hide’:表示產(chǎn)生所有圖片,但是并不展示 fig.width:設(shè)置圖片輸出的寬度? fig.height:設(shè)置圖片輸出的高度? fig.align
設(shè)置圖片位置排版格式,默認(rèn)為left,可以為right或者center?fig.cap :設(shè)置圖片的標(biāo)題 fig.subcap:設(shè)置圖片的副標(biāo)題?

2.2markdown的圖表輸出
knitr::kable(head(rock), caption = 'rock數(shù)據(jù)',align='c')

x_html <- knitr:: kable(head(rock), "html")
kableExtra::kable_styling(x_html,bootstrap_options = "striped",
full_width = F)

x_html <- knitr:: kable(head(rock), "html")
kableExtra::kable_styling(x_html,bootstrap_options = "striped",
full_width = F,
position = "left")

x_html <- knitr:: kable(head(rock), "html")
kableExtra::kable_styling(x_html,bootstrap_options = "striped",
full_width = T,
font_size = 20

x_html <- knitr:: kable(head(rock), "html")
x_html <- kableExtra::kable_styling(x_html,
bootstrap_options = "striped",
full_width = T)
kableExtra::column_spec(x_html,1:2,
bold = T,
color = "white",
background = "#D7261E")

x_html <- knitr:: kable(head(rock), "html")
x_html <- kableExtra::kable_styling(x_html,
bootstrap_options = "striped",
full_width = T)
kableExtra::row_spec(x_html,1:2,
bold = T,
color = "white",
background = "#D7261E")

library(kableExtra)
data = plyr::mutate(rock[1:10, ],
perm = cell_spec(perm,"html",
color = "white",
bold = T,
background = spec_color(1:10,
end = 0.9,
option = "A",
direction = -1)),
shape = ifelse(shape > 0.15,
cell_spec(shape,
"html",
color = "white",
background = "#D7261E",
bold = T),
cell_spec(shape, "html",
color = "green",
bold = T)))
x_html <-knitr::kable(data,"html", escape = F, align = "c")
x_html <-row_spec(x_html,0, color = "white", background = "#696969" )
kable_styling(x_html,"striped")

2.3markdown的主題格式
---
title: "建立你的markdown項(xiàng)目"
author: "R友舍"
date: "2020/9/1"
output:
rmdformats::readthedown:
self_contained: true
thumbnails: true
lightbox: true
gallery: false
highlight: tango
---

---
title: "建立你的markdown項(xiàng)目"
author: "R友舍"
date: "2020/9/1"
output:
prettydoc::html_pretty:
theme: cayman
highlight: github
---

---
title: "建立你的markdown項(xiàng)目"
author: "R友舍"
date: "2020/9/1"
output:
tufte::tufte_html: default
---

---
title: "建立你的markdown項(xiàng)目"
author: "R友舍"
date: "2020/9/1"
output:
html_document:
theme: cerulean
highlight: tango
---

2.4markdown的導(dǎo)出

input
指定需要導(dǎo)出的rmarkdwon文件地址output_format
指定需要導(dǎo)出的文件類型,同樣支持pdf、word、html等多種文件格式。若未指定output_format格式,則輸出rmarkdown文件中output指定的格式類型。
3、生成可重復(fù)性報(bào)告


name <-"airquality"
render("用rmarkdown定制你的數(shù)據(jù)分析報(bào)告/可重復(fù)分析報(bào)告/模版.Rmd",
params = list(name=name),
output_file = paste0(name,'數(shù)據(jù)集概覽'),
)
library(datasets)
name_list <-c("airquality","mtcars","LifeCycleSavings")
for(name in name_list){
render("用rmarkdown定制你的數(shù)據(jù)分析報(bào)告/可重復(fù)分析報(bào)告/模版.Rmd",
params = list(name=name),
output_file = paste0(name,'數(shù)據(jù)集概覽'),
)
}

往期精品(點(diǎn)擊圖片直達(dá)文字對(duì)應(yīng)教程)
后臺(tái)回復(fù)“生信寶典福利第一波”或點(diǎn)擊閱讀原文獲取教程合集

評(píng)論
圖片
表情



























