箱线图走一个

作者: 小洁忘了怎么分身 | 来源:发表于2019-02-11 11:23 被阅读5次
# 从内置数据集的表达矩阵中找TP53基因的表达量
rm(list=ls())
options(stringsAsFactors = F)
if(!suppressMessages(require("hgu95av2.db")))BiocManager::install("hgu95av2.db")
if(!suppressMessages(require("CLL")))BiocManager::install("CLL")
if(!suppressMessages(require(tidyverse)))install.packages("tidyverse")
if(!suppressMessages(require(ggpubr)))install.packages("ggpubr")
suppressMessages(library(hgu95av2.db))
suppressMessages(library(CLL))
suppressMessages(library(ggpubr))

data(sCLLex)
# sCLLex
exprSet <- exprs(sCLLex) #探针的表达量
exprSet[1:4,1:4]
#>           CLL11.CEL CLL12.CEL CLL13.CEL CLL14.CEL
#> 1000_at    5.743132  6.219412  5.523328  5.340477
#> 1001_at    2.285143  2.291229  2.287986  2.295313
#> 1002_f_at  3.309294  3.318466  3.354423  3.327130
#> 1003_s_at  1.085264  1.117288  1.084010  1.103217
pd <- pData(sCLLex) #sampleID与disease的对应关系
head(pd)
#>           SampleID  Disease
#> CLL11.CEL    CLL11 progres.
#> CLL12.CEL    CLL12   stable
#> CLL13.CEL    CLL13 progres.
#> CLL14.CEL    CLL14 progres.
#> CLL15.CEL    CLL15 progres.
#> CLL16.CEL    CLL16 progres.

p2s <- toTable(hgu95av2SYMBOL) #探针与symbol的对应关系
head(p2s)
#>    probe_id  symbol
#> 1   1000_at   MAPK3
#> 2   1001_at    TIE1
#> 3 1002_f_at CYP2C19
#> 4 1003_s_at   CXCR5
#> 5   1004_at   CXCR5
#> 6   1005_at   DUSP1

p3 <- filter(p2s,symbol=='TP53')

# boxplot [find TP53 has 3 probe IDs]
probe_tp53 <- p3$probe_id
for(i in 1:3){
boxplot(exprSet[probe_tp53[i],] ~ pd$Disease)
}
#用ggpubr作图
#http://www.sthda.com/english/articles/24-ggpubr-publication-ready-p#lots/
expd <- rownames_to_column(as.data.frame(exprSet))
expd[1:4,1:4]
#>     rowname CLL11.CEL CLL12.CEL CLL13.CEL
#> 1   1000_at  5.743132  6.219412  5.523328
#> 2   1001_at  2.285143  2.291229  2.287986
#> 3 1002_f_at  3.309294  3.318466  3.354423
#> 4 1003_s_at  1.085264  1.117288  1.084010
expd2 <- gather(expd,
                   key = 'sample',
                   value = 'exp',-1)
pd <- rownames_to_column(pd)
head(pd)
#>     rowname SampleID  Disease
#> 1 CLL11.CEL    CLL11 progres.
#> 2 CLL12.CEL    CLL12   stable
#> 3 CLL13.CEL    CLL13 progres.
#> 4 CLL14.CEL    CLL14 progres.
#> 5 CLL15.CEL    CLL15 progres.
#> 6 CLL16.CEL    CLL16 progres.
expd3 <- inner_join(expd2,pd,by=c('sample'='rowname'))
i=1 ###可换1,2
for(i in 1:3){
p <- ggboxplot(filter(expd3,rowname==probe_tp53[i]), 
               x = 'Disease',
               y = 'exp',
               color = "Disease", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
               add = "jitter", shape = "Disease")
print(p)
}


相关文章

  • 箱线图走一个

  • 如果绘制箱线图-Excel2013

    文章简介 继续学习,这次学习了箱线图的概念、四分位数计算以及箱线图的绘制,分享给大家。 箱线图简介 箱线图(Box...

  • R绘图

    heatmap pheatmap 实例 其他1 其他2 其他3 线图1 线图2 箱线图1 箱线图2 火山图 韦恩...

  • seaborn实例-boxplot-箱线图

    关于箱线图的理论,参考:箱线图(Box Plot)理论篇 这一篇看看seaborn中绘制箱线图 seaborn.b...

  • R语言绘制核密度图,箱线图,小提琴图,点图

    数据 模型 核密度图 可比较的核密度图 箱线图 简单箱线图 交叉因子箱线图 小提琴图 点图

  • 箱线图你真的懂了吗?

    箱线图的理解,以下先画出一个箱线图 箱线图上下两边是75% 25%分位数,箱子中部的线表示中位数,上下两边的距离称...

  • R语言可视化(七):箱线图绘制

    07.箱线图绘制 清除当前环境中的变量 设置工作目录 基础boxplot函数绘制箱线图 ggplot2包绘制箱线图...

  • 认识matplotlib—直方图、饼图、箱线图

    本节主要介绍如何绘制直方图、饼图、箱线图。 直方图 饼图 箱线图

  • 箱线图

    箱线图五要素: 最大值 四分之三分位数 中位数 (图中红线) 四分之一分位数 最小值

  • 箱线图

    箱线图适合直观展示数据的分布。下图显示箱线图的构成,实际作图也可以根据自己需要进行一定调整/取舍。 其中 m 是中...

网友评论

    本文标题:箱线图走一个

    本文链接:https://www.haomeiwen.com/subject/lfrfeqtx.html