今天小果绘制一下基因在不同组织中差异表达的泡泡图,代码如下:
- 安装所需要的R包
install.packages(“ggplot2”)
install.packages(“tidyverse”)
BiocManager::install(“ComplexHeatmap”)
- 导入需要的R包
library(ggplot2)
library(tidyverse)
library(ComplexHeatmap)
3读取数据
exprTab<-read.table(“expr.txt”,header=T)
4.代码展示
# 产生泡泡图
orange <- “#E45737”
green <- “#6F8B35”
blue <- “#4577FF”
red <- “#C2151A”
#确定基因因子顺序
exprTab$gene <- factor(exprTab$gene,
levels=rev(c(“CDKN1A”,”HSPA5″,”TTC35″,”SLC7A11″,”NFE2L2″,”MT1G”,”HSPB1″,”GPX4″,”FANCD2″,”CISD1″, “FDFT1″,”SLC1A5″,”SAT1″,”TFRC”,”RPL8″,”NCOA4″,”LPCAT3″,”GLS2″,”DPP4″,”CS”,”CARS”,”ATP5G3″,”ALOX15″,”ACSL4″)))
my_palette <- colorRampPalette(c(green,”white”,orange), alpha=TRUE)(n=128)
p <- ggplot(exprTab, aes(x=tumor,y=gene)) +
geom_point(aes(size=-log10(FDR),color=log2fc)) +
scale_color_gradientn(‘log2(FC)’,
colors=my_palette) +
theme_bw() +
theme(#panel.grid.minor = element_blank(),
#panel.grid.major = element_blank(),
axis.text.x = element_text(angle = 45, size = 12, hjust = 0.3, vjust = 0.5, color = “black”),
axis.text.y = element_text(size = 12, color = rep(c(red,blue),c(14,10))),
axis.title = element_blank(),
panel.border = element_rect(size = 0.7, linetype = “solid”, colour = “black”),
plot.margin = unit(c(0,0,1,1), “lines”))
ggsave( p,file=”Bubbleplot.pdf”, width = 8, height = 8)
泡泡图最终完整的展现出来了,有需要的小伙伴可以借鉴学习奥。