## 多組boxplot
### 應用場景
eg: 展示多個基因在腫瘤和正常組織中的表達量
```R
# 多組boxplot
# 構建數據集
rt_box_m <- data.frame(cbind(c(as.numeric(rt['TP53',]), as.numeric(rt['CD274',]), as.numeric(rt['LAMA3', ])),
c(rep('TP53', 114), rep('CD274', 114), rep('LAMA3', 114)),
rep(c(rep('tumor', 57), rep('normal', 57)), 3)), stringsAsFactors = FALSE)
colnames(rt_box_m) <- c('expression', 'gene_name', 'group')
rt_box_m$expression <- as.numeric(rt_box_m$expression)
```
> 數據結構如下

```R
library(ggpubr)
PP1 <- ggplot(rt_box_m, aes(x = gene_name, y = expression)) +
geom_boxplot(aes(fill = group), position = position_dodge(0.9))
print(PP1)
# 利用stat_compare_means添加統計檢驗的pvalue
PP2 <- PP1 + stat_compare_means(aes(group = group), label = "p.format")
print(PP2)
### 利用theme_classic改變主題
PP3 <- PP2 + theme_classic()
print(PP3)
```



### 分面展示這些結果
```R
PF1 <- ggplot(rt_box_m, aes(group, expression)) +
geom_boxplot(aes(color = group))+
facet_grid(. ~ gene_name) + #改變分面展示的方向
scale_color_manual(values = c("blue", "red")) + #修改box的顏色
stat_compare_means(label = "p.format")
print(PF1)
PF2 <- ggplot(rt_box_m, aes(group, expression)) +
geom_boxplot(aes(color = group))+
facet_grid(gene_name ~ .) +
scale_color_manual(values = c("blue", "red")) +
stat_compare_means(label = "p.format")
print(PF2)
```


- 智匯醫圈
- 第一章 前言
- 1.1 簡介
- 1.2 制作該教程的目的
- 1.3 學習該教程需要掌握的基礎知識
- 1.4 該教程適用人群
- 第二章 散點圖(scatter plot)
- 2.1 基本的散點圖
- 2.2 3D 散點圖
- 第三章 線圖(line plot)
- 3.1 基本的線圖
- 第四章 箱型圖(boxplot)
- 4.1 基本的箱型圖
- 4.2 圖形參數調整
- 4.3 多分組箱型圖
- 4.4 小提琴圖
- 第五章 密度圖(density plot)
- 5.1 基本的密度圖
- 第六章 熱圖(Heatmap)
- 6.1 基本的熱圖
- 6.2 ggplot2 heatmap
- 6.3 相關性熱圖
- 第七章 主成分分析(PCA)
- 7.1 2D PCA
- 7.2 3D PCA
- 第八章 ROC 曲線
- 8.1 基本的 ROC 曲線
- 第九章 生存分析(KM plot)
- 9.1 基本的生存分析
- 第十章 KEGG 和 GO 分析
- 10.1 KEGG 分析
- 10.2 GO 分析
- 第十一章 Circular plot
- 11.1 基本的 Circular plot
- 附錄 下載數據