# R 樣板紀錄 一些用 R script 呈現 素材版圖。 ### 火山圖 ![](https://i.imgur.com/TZvxNuw.png) ``` #nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") #nba <- nba[order(nba$PTS),] #row.names(nba) <- nba$Name #nba <- nba[,2:20] #nba_matrix <- data.matrix(nba) #nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) DE <- read.table("diffExpr.P0.001_C1.matrix.log2_1.dat.txt",header=T, sep="\t") DE <- DE[order(DE$gene),] row.names(DE) <- DE$gene DE_V <- DE[,1:9] DE_matrix <- data.matrix(DE_V) DE_heatmap <- heatmap(DE_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) ``` ### Veen diagram 數量差異比較。 不過要先用 perl 計算好值與排列好資料格式 ![](https://i.imgur.com/LcuqBAn.png) ``` fonts() ## 查詢字體 grid.newpage(); venn.plot <- draw.pairwise.venn( area1 = 1476+2090, area2 = 794+2090, cross.area = 2090, fill = c("blue", "green"), alpha = rep(0.3, 2), category= c("Brain vs. Liver", "Gill vs. Liver"), cat.pos = c(-20, 20), cat.dist = 0.05, euler.d = TRUE, cex=3, cat.cex= 2, fontfamily="Arial Black", cat.fontfamily="Arial Black" ); ``` ![](https://i.imgur.com/vCNd1uM.png) ``` ## REFERENCE * for use draw.pairwise.venn( * area1, * area2, * cross.area, category = rep("", 2), euler.d = TRUE, scaled = TRUE, inverted = FALSE, ext.text = TRUE, ext.percent = rep(0.05, 3), lwd =rep(2, 2), lty = rep("solid", 2), col = rep("black",2), * fill = NULL, * alpha = rep(0.5, 2), label.col = rep("black", 3), cex = rep(1, 3), fontface =rep("plain", 3), fontfamily = rep("serif", 3), * cat.pos= c(-50, 50), * cat.dist = rep(0.025, 2), cat.cex =rep(1, 2), cat.col = rep("black", 2), cat.fontface = rep("plain", 2), cat.fontfamily = rep("serif", 2), cat.just = rep(list(c(0.5, 0.5)), 2), cat.default.pos = "outer", cat.prompts = FALSE, ext.pos = rep(0, 2), ext.dist = rep(0, 2), ext.line.lty = "solid", ext.length = rep(0.95, 2), ext.line.lwd = 1, rotation.degree = 0, rotation.centre = c(0.5, 0.5), ind = TRUE, sep.dist = 0.05, offset = 0, cex.prop = NULL, print.mode = "raw", sigdigs = 3) ``` ### Heatmap ![](https://i.imgur.com/e6kBQpe.png) ``` hhh_1 <- read.table(file="molecular_function_count_1",sep="\t",header= T) hhh <- read.table(file="molecular_function_count",sep="\t",header= T) len <- as.vector(hhh$term) qvalue<-as.numeric(hhh_1$p.value) ``` ### heatmap 變形圖 用顏色梯度與形狀大小來丞相三個維度的資料。 ![](https://i.imgur.com/EHvueg1.png) ``` p <- ggplot(hhh_1, aes(x=type ,y=term, fill=p.value))+labs(fill='p.value\n')+labs(x = "",y = "") p +geom_point()+geom_tile( colour="black") + theme_bw(16)+scale_y_discrete(limits=len)+scale_fill_gradientn(colours=heat.colors(50), breaks=c(0,0.05,1) ,labels=c("",0.05,1),limits=c(0,1), space = "Lab",na.value = "white", guide = "colourbar")+theme(axis.text.x = element_text(angle=30, hjust=.9, vjust=.9,size=14),axis.text=element_text(size=14)) ggsave("label.pdf", width=5.5, height=4) ``` # 長度分布 ![](https://i.imgur.com/RmupQKM.png) ``` setwd("E:/____do_test/R_studio/transcriptome_distribution") list500 <- read.table(file="500_5k_re.txt", header =TRUE, sep="\t") list500_1 <- read.table(file="500_5k_re_1.txt", header =TRUE, sep="\t") len500 <- as.vector(list500$lenght.kb.) library("ggplot2", lib.loc="~/R/win-library/3.3") plot500 <- ggplot(list500_1,aes(x=lenght.kb., y=count, fill=type)) + geom_bar(stat="identity", position="dodge") + scale_fill_brewer(palette="Pastel1") + theme(axis.text.x = element_text(angle=70, hjust=1, vjust=.5))+xlab("length range (nt)") + ylab("counts")+scale_x_discrete(limits=len500)+ ggtitle("Transcript Length Distribution")+labs(fill='transcriptome\n')+ theme(legend.justification=c(0.95,0.95), legend.position=c(0.95,0.95), legend.title = element_text(colour="black", size=16, face="bold"),legend.text = element_text( size = 14),axis.text=element_text(size=12),axis.title=element_text(size=14,face="bold")) plot500 ggsave("myplot500_5k_2_3-1.pdf", width=8, height=5) plot500 <- ggplot(list500_1,aes(x=lenght.kb., y=count, fill=type)) + geom_bar(stat="identity", position="dodge") + scale_fill_brewer(palette="Pastel1") + theme(axis.text.x = element_text(angle=60, hjust=1, vjust=.5))+xlab("\n\nlength range (nt)") + ylab("counts\n") +scale_x_discrete(limits=len500)+ ggtitle("Transcript Length Distribution")+labs(fill='transcriptome\n')+ theme(legend.justification=c(0.95,0.95), legend.position=c(0.95,0.95), legend.title = element_text(colour="black", size=16, face="bold"),legend.text = element_text(size = 14),axis.text=element_text(size=12),axis.title=element_text(size=14,face="bold")) plot500 ggsave("myplot500_5k_3.pdf", width=8, height=5) plot500+geom_text(aes(label=count), vjust=-0.5, colour="black",position=position_dodge(.9), size=2, angle=50) ggsave("myplot500_5k_1.pdf", width=9, height=5) ```