赞
踩
有了R语言的基础,以及ggplot2绘图基础,我们的生信常用分析图形的绘制就可以提上日程了!本系列,师兄就开始带着大家一起学习如何用R语言绘制我们自己的各种分析图吧!
由于本系列的所有分析代码均为师兄细心整理和详细注释而成的!欢迎点赞、收藏、转发!
您的支持是我持续更新的最大动力!
系列内容包括:
############## data <- read.csv("DEG.csv",row.names = 1) color <- rep("#999999",nrow(data)) color[data$pvalue <0.05 & data$log2FoldChange > 1] <- "#FC4E07" color[data$pvalue <0.05 & data$log2FoldChange < -1] <- "#00AFBB" par(oma = c(0,2,0,0)) plot(data$log2FoldChange,-log10(data$pvalue),pch = 16,cex = 0.5, xlim = c(-4,4), ylim = c(0,32), col = color, frame.plot = F, xlab = "log2FC", ylab = "-log10(Pvalue)", cex.axis = 1, cex.lab = 1.3) # 添加参考线: abline(h = -log10(0.05),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型; abline(v = c(-1,1),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型; # 添加图例 legend(x = 3, y = 32, legend = c("Up","Normal","Down"), bty = "n", # 去除边框 pch = 19,cex = 1, # 设置点的样式和大小 x.intersp = 0.3, # 设置字与点之间的距离; y.intersp = 0.3, # 设置点与点的高度差,相当于行距; col = c("#FC4E07","#999999","#00AFBB")) # 添加标签: color = c() color[which(data[1:10,]$regulate == "Up")] = "#FC4E07" color[which(data[1:10,]$regulate != "Up")] = "#00AFBB" text(data$log2FoldChange[1:10],-log10(data$pvalue)[1:10], labels = data$row[1:10], adj = c(0,1.5), cex = 0.6, col = color)
# 包装函数: # 调整1: xlim和ylim得去掉 # 调整2: 修改图例的位置 plotVoc <- function(data){ color <- rep("#999999",nrow(data)) color[data$pvalue <0.05 & data$log2FoldChange > 1] <- "#FC4E07" color[data$pvalue <0.05 & data$log2FoldChange < -1] <- "#00AFBB" par(oma = c(0,2,0,0)) plot(data$log2FoldChange,-log10(data$pvalue),pch = 16,cex = 0.5, col = color, frame.plot = F, xlab = "log2FC", ylab = "-log10(Pvalue)", cex.axis = 1, cex.lab = 1.3) # 添加参考线: abline(h = -log10(0.05),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型; abline(v = c(-1,1),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型; # 添加图例 legend(x = 3, y = max(-log10(data$pvalue)), legend = c("Up","Normal","Down"), bty = "n", # 去除边框 pch = 19,cex = 1, # 设置点的样式和大小 x.intersp = 0.3, # 设置字与点之间的距离; y.intersp = 0.3, # 设置点与点的高度差,相当于行距; col = c("#999999", "#FC4E07","#00AFBB")) # 添加标签: color = c() color[which(data[1:10,]$regulate == "Up")] = "#FC4E07" color[which(data[1:10,]$regulate != "Up")] = "#00AFBB" text(data$log2FoldChange[1:10],-log10(data$pvalue)[1:10], labels = data$row[1:10], adj = c(0,1.5), cex = 0.6, col = color) } data <- read.csv("DEG2.csv",row.names = 1) plotVoc(data)
library(ggplot2) data <- read.csv("DEG.csv",row.names = 1) ################# # ggplot2绘制火山图 data$label <- c(rownames(data)[1:10],rep(NA,nrow(data) - 10)) ggplot(data,aes(log2FoldChange,-log10(pvalue),color = regulate)) + xlab("log2FC") + geom_point(size = 0.6) + scale_color_manual(values=c("#00AFBB","#999999","#FC4E07")) + geom_vline(xintercept = c(-1,1), linetype ="dashed") + geom_hline(yintercept = -log10(0.05), linetype ="dashed") + theme(title = element_text(size = 15), text = element_text(size = 15)) + theme_classic() + geom_text(aes(label = label),size = 3, vjust = 1,hjust = -0.1)
############# # 使用ggpurb绘制火山图: library(ggpubr) data$pvalue <- -log10(data$pvalue) ggscatter(data, x = "log2FoldChange", y = "pvalue", ylab="-log10(P.value)", size=0.6, color = "regulate", label = rownames(data), label.select = rownames(data)[1:10], repel = T, palette = c("#00AFBB", "#999999", "#FC4E07")) + geom_hline(yintercept = 1.30,linetype ="dashed") + geom_vline(xintercept = c(-1,1),linetype ="dashed")
以上内容仅为群内部分内容,不代表全部。详细目录请看下方列表!已经入群的小伙伴,无需付费购买推文,群内都会及时更新!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。