气泡图
可以利用圆圈的大小和颜色呈现不同的信息。
颜色=大小
上图可以很明显的比较不同癌症中,重点基因的表达上调,下调情况。
输入数据:
CancerType SEMA3A SEMA3B SEMA3C SEMA3D SEMA3E SEMA3F SEMA3G ACC 0.3058794 0.6749167 1.553152 0.5609269 0.04308815 2.26759 1.071968 BLCA 0.2604646 2.000748 2.540686 3.206074 0.1042546 5.011131 0.973269 BRCA 0.670601057 4.377172833 4.029076017 0.737759733 0.91107385 5.417881198 2.049093333 CESC 0.030040274 3.10372984 0.856697707 0.003915114 0 5.456114412 0.132489277 CHOL 0.095912868 4.07200434 1.314131662 0.600759078 1.992685462 2.314930492 0.987326396 COAD 0.873017985 3.451703237 3.127341383 0.013969328 0.005579384 4.008015946 0.209814414 DLBC 0.272125554 0.219965593 1.397671738 0.109106107 0 1.996505875 0.975258625 ESCA 0.544115639 3.507967898 2.424222105 0.020936575 1.483539393 4.889857263 1.820995419 GBM 1.94317517 2.684062356 0.839038003 0.259588685 0.846527302 1.794908944 1.009469544 HNSC 2.311874186 2.07577583 4.365968393 2.789724274 0.255179005 4.492226761 0.936592175 KICH 0.1803919 0.7990171 2.33629 0.2293381 0.008582394 6.087315 3.024843 KIRC 0.244401766 1.558844062 1.753992572 1.399060231 0.008017802 5.122464213 1.920018423 KIRP 0.181453169 4.41545663 2.743989829 0.075370437 0.162205209 3.06193522 1.411410981 LAML 0.061109013 0.236436959 1.292188066 0 0.005767489 1.742797077 0.25603614 LGG 0.45521916 5.099739943 1.511859575 1.471356421 0.31653094 0.425500578 2.050405054 LIHC 0.04540965 1.999732 0.0717533 0.02480912 0 2.804368 0.7499197 LUAD 2.447074057 4.575235422 2.617218951 0.422363027 0.268892634 2.660777231 1.455641511 LUSC 0.594260148 0.639515371 2.319055716 0.07517063 0.062451757 4.202372562 0.811142418 MESO 0.29529343 4.576696133 5.579111428 0.300853327 0.463107847 2.96484522 0.673253843 OV 0.607179331 4.786856448 3.853027384 0.181927986 0.116899632 4.669398164 1.765830259 PAAD 0.7162406 0.8992736 0.6019803 0.04994482 0.472778 2.207573 2.329929 PCPG 0.094462773 2.028825356 1.256253813 0.08269041 0.012272302 2.188914513 3.088547101 PRAD 0.3908217 1.142047 5.156465 2.39914 1.583892 2.966339 1.002553 READ 0.720759497 2.831257616 2.899446575 0 0 5.247167593 1.308290664 SARC 0.488146647 3.577916624 4.32198378 1.120329044 0.008985208 2.731882694 3.413901154 SKCM 2.638949 4.913505 5.401904 0.293977 0 1.845956 1.084495 STAD 0.47690858 4.297823133 3.304884099 0.080311232 0.065753996 3.166858468 0.611160518 TGCT 1.259307349 2.52271991 0.67248451 0.169443112 0.529362333 3.156383791 1.186455429 THCA 0.138214622 2.021548245 0.757462935 0.12121475 2.141452093 3.390107498 1.68488299 THYM 0.498055011 1.428231405 1.69062676 3.148596065 2.048798365 7.224941304 0.948677739 UCEC 0.083812554 1.639466861 2.145916633 0.153562717 0.494608775 4.628178397 0.53350085 UCS 2.917264867 2.397795149 4.81695624 0.191347885 0.818735876 5.247746402 0.213337442 UVM 0.021517288 2.868286214 4.65984434 0.007181645 0.046549024 0.945125876 0.361792439
代码:
library(ggpubr) inputFile <- "input.txt" # 输入文件 outFile <- "ggballoonplot.pdf" # 输出文件 setwd("") # 读取文件 data <- read.table(inputFile, header = T, sep = "\t", check.names = F, row.names = 1) # 绘制气泡图 p <- ggballoonplot(data, fill = 'value') + # 按“值”的大小填充颜色 gradient_fill(c("blue", "white", "red")) # 更改渐变颜色 # 输出图片文件 pdf(file = outFile, width = 8, height = 7) print(p) dev.off()
但是由于上图中颜色和大小都是以“value”来定义的,所以只能显示基因表达量的信息,而不能看出各基因差异表达的P值。
我们可以分别指定圆圈颜色和大小所对应的值,就可以展示更多的信息:
颜色≠大小
输入数据:(同上)
CancerType SEMA3A SEMA3B SEMA3C SEMA3D SEMA3E SEMA3F SEMA3G ACC 0.3058794 0.6749167 1.553152 0.5609269 0.04308815 2.26759 1.071968 BLCA 0.2604646 2.000748 2.540686 3.206074 0.1042546 5.011131 0.973269 BRCA 0.670601057 4.377172833 4.029076017 0.737759733 0.91107385 5.417881198 2.049093333 CESC 0.030040274 3.10372984 0.856697707 0.003915114 0 5.456114412 0.132489277 CHOL 0.095912868 4.07200434 1.314131662 0.600759078 1.992685462 2.314930492 0.987326396 COAD 0.873017985 3.451703237 3.127341383 0.013969328 0.005579384 4.008015946 0.209814414 DLBC 0.272125554 0.219965593 1.397671738 0.109106107 0 1.996505875 0.975258625 ESCA 0.544115639 3.507967898 2.424222105 0.020936575 1.483539393 4.889857263 1.820995419 GBM 1.94317517 2.684062356 0.839038003 0.259588685 0.846527302 1.794908944 1.009469544 HNSC 2.311874186 2.07577583 4.365968393 2.789724274 0.255179005 4.492226761 0.936592175 KICH 0.1803919 0.7990171 2.33629 0.2293381 0.008582394 6.087315 3.024843 KIRC 0.244401766 1.558844062 1.753992572 1.399060231 0.008017802 5.122464213 1.920018423 KIRP 0.181453169 4.41545663 2.743989829 0.075370437 0.162205209 3.06193522 1.411410981 LAML 0.061109013 0.236436959 1.292188066 0 0.005767489 1.742797077 0.25603614 LGG 0.45521916 5.099739943 1.511859575 1.471356421 0.31653094 0.425500578 2.050405054 LIHC 0.04540965 1.999732 0.0717533 0.02480912 0 2.804368 0.7499197 LUAD 2.447074057 4.575235422 2.617218951 0.422363027 0.268892634 2.660777231 1.455641511 LUSC 0.594260148 0.639515371 2.319055716 0.07517063 0.062451757 4.202372562 0.811142418 MESO 0.29529343 4.576696133 5.579111428 0.300853327 0.463107847 2.96484522 0.673253843 OV 0.607179331 4.786856448 3.853027384 0.181927986 0.116899632 4.669398164 1.765830259 PAAD 0.7162406 0.8992736 0.6019803 0.04994482 0.472778 2.207573 2.329929 PCPG 0.094462773 2.028825356 1.256253813 0.08269041 0.012272302 2.188914513 3.088547101 PRAD 0.3908217 1.142047 5.156465 2.39914 1.583892 2.966339 1.002553 READ 0.720759497 2.831257616 2.899446575 0 0 5.247167593 1.308290664 SARC 0.488146647 3.577916624 4.32198378 1.120329044 0.008985208 2.731882694 3.413901154 SKCM 2.638949 4.913505 5.401904 0.293977 0 1.845956 1.084495 STAD 0.47690858 4.297823133 3.304884099 0.080311232 0.065753996 3.166858468 0.611160518 TGCT 1.259307349 2.52271991 0.67248451 0.169443112 0.529362333 3.156383791 1.186455429 THCA 0.138214622 2.021548245 0.757462935 0.12121475 2.141452093 3.390107498 1.68488299 THYM 0.498055011 1.428231405 1.69062676 3.148596065 2.048798365 7.224941304 0.948677739 UCEC 0.083812554 1.639466861 2.145916633 0.153562717 0.494608775 4.628178397 0.53350085 UCS 2.917264867 2.397795149 4.81695624 0.191347885 0.818735876 5.247746402 0.213337442 UVM 0.021517288 2.868286214 4.65984434 0.007181645 0.046549024 0.945125876 0.361792439
data1:
代码:
library(ggpubr) inputFile <- "input.txt" # 输入文件 outFile <- "ggballoonplot1.pdf" #输出文件 setwd("") # 读取文件并按需修改 data <- read.table(inputFile, header = T, sep = "\t", check.names = F, row.names = 1) data1 <- data data1$type <- rownames(data) data1 <- data1[,c(8,1:7)] data1 <- melt(data1, id.vars = "type") data1$P.value <- runif(231,0,0.07) # 随机生成P值,用于举例 colnames(data1) <- c("Type","Gene","Value", "P.value") data1$Type <- factor(data1$Type) data1$Type <- factor(data1$Type, levels = rev(levels(data1$Type))) # 绘制气泡图 p1 <- ggballoonplot(data1, x = "Gene", y = "Type", # x轴和y轴的意义 fill = "P.value", # 按“P.value”的值填充颜色 size = "Value") + # 按“Value”的值设置圆圈的大小 gradient_fill(c("blue", "white", "red")) # 更改渐变颜色 # 输出图形文件 pdf(file = outFile, width = 8, height = 7) print(p1) dev.off()
两张图放在一起对比一下: