時(shí)間:2019.7.4
內(nèi)容:初級(jí)題與中級(jí)題
分組
> plate <- as.data.frame(plate)
> e$plate <- plate###將plate加入e中成為plate列
> e1 <- e[e$plate=='0048']
> class(e1)
[1] "character"
> dim(e1) <- c(384,3)
> class(e1)
[1] "matrix"
> e2 <- e[e$plate=='0049']
> dim(e2) <- c(384,3)
> e1 <- e1[,-2]
> e2 <- e2[,-2]
> e1 <- as.numeric(e1)
> dim(e1 ) <- c(384,2)
> class(e1[,1])
[1] "numeric"
> colnames(e1) <- c('MBases','plate')
> e2 <- as.numeric(e2)
> dim(e2) <- c(384,2)
> colnames(e2) <- c('MBases','plate')
頻數(shù)圖
> hist(e1[,1])
image.png
> hist(e2[,1])
image.png
使用ggplot2畫(huà)圖
箱圖
library(ggplot2)
class(e1)
e1 <- as.data.frame(e1)
e2 <- as.data.frame(e2)
> ggplot(e1,aes(x=plate,y=MBases))+geom_boxplot()
> ggplot(e2,aes(x=plate,y=MBases))+geom_boxplot()
image.png
image.png
頻數(shù)圖
> ggplot(e1,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
> ggplot(e2,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
image.png
> ggplot(e2,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
image.png
密度圖
> ggplot(e1,aes(x=MBases))+geom_density()
image.png
> ggplot(e2,aes(x=MBases))+geom_density()
image.png
使用ggpubr作圖
library(ggpubr)
箱圖
> ggboxplot(e1,x = 'plate',y = 'MBases')
image.png
> ggboxplot(e2,x = 'plate',y = 'MBases')
image.png
頻數(shù)圖
> gghistogram(e1,x='MBases',bins=30)
image.png
> gghistogram(e2,x='MBases',bins=30)
image.png
密度圖
> ggdensity(e1,x='MBases')
image.png
> ggdensity(e2,x='MBases')
image.png
隨機(jī)取384個(gè)MBases信息悠栓,跟前面的兩個(gè)plate的信息組合成新的數(shù)據(jù)框那先,第一列是分組,第二列是MBases,總共是384*3行數(shù)據(jù)棉胀。
> a1 <- e$MBases[1:384]
> a2 <- e$Title[1:384]
> a <- data.frame(a1,a2)
> a$plate <- as.data.frame(plate[,1][1:384])
> colnames(a) <- c('MBases','Title','plate')
中級(jí)題
作業(yè) 1
根據(jù)R包org.Hs.eg.db找到下面ensembl 基因ID 對(duì)應(yīng)的基因名(symbol)
> g2s <- toTable(org.Hs.egSYMBOL)
> g2e <- toTable(org.Hs.egENSEMBL)
> ensemble_id <- c('ENSG00000000003.13','ENSG00000000005.5','ENSG00000000419.11','ENSG00000000457.12','ENSG00000000460.15','ENSG00000000938.11')
> #批量取基因名
> library(stringr)
> unlist(str_split(ensemble_id,'[.]'))
[1] "ENSG00000000003" "13" "ENSG00000000005" "5"
[5] "ENSG00000000419" "11" "ENSG00000000457" "12"
[9] "ENSG00000000460" "15" "ENSG00000000938" "11"
> tmp <- unlist(str_split(ensemble_id,'[.]',simplify = T))###simplify = T 此參數(shù)生成為矩陣
image.png
> class(unlist(str_split(ensemble_id,'[.]',simplify = T)))
[1] "matrix"
> ensemble_id <- tmp[,1]
> ensembl_id <- as.data.frame(ensemble_id)
image.png
> colnames(ensembl_id) <- 'ensembl_id'
> merge1 <- merge(x=ensembl_id,y=g2e,by='ensembl_id')
image.png
> merge2 <- merge(x=merge1,y=g2s,by='gene_id')
image.png
作業(yè) 2
根據(jù)R包hgu133a.db找到下面探針對(duì)應(yīng)的基因名(symbol)
> tmp <- c('1053_at','117_at','121_at','1255_g_at','1316_at','1320_at','1405_i_at','1431_at','1438_at','1487_at','1494_f_at','1598_g_at','160020_at','1729_at','177_at')
> probe_id <- as.data.frame(tmp)
> View(probe_id)
> colnames(probe_id) <- 'probe_id'
> View(probe_id)
image.png
> a <- toTable(hgu133aSYMBOL)
> merge <- merge(x=probe_id,y=a,by='probe_id')
image.png