在一个面板中放置多个图

时间:2018-08-22 21:26:15

标签: r grid facet ggpubr

我正在尝试使用ggpubr软件包中的ggscatter函数在R中绘制散点图。我正在向您展示我的数据的一部分。

tracking_id gene_short_name B1  B2  C1  C2
ENSG00000000003.14  TSPAN6  1.2 1.16    1.22    1.26
ENSG00000000419.12  DPM1    1.87    1.87    1.68    1.83
ENSG00000000457.13  SCYL3   0.59    0.63    0.82    0.69
ENSG00000000460.16  C1orf112    0.87    0.99    0.97    0.83
ENSG00000001036.13  FUCA2   1.59    1.59    1.4 1.39
ENSG00000001084.10  GCLC    1.43    1.55    1.46    1.32
ENSG00000001167.14  NFYA    1.2 1.3 1.39    1.21
ENSG00000001460.17  STPG1   0.43    0.46    0.34    0.76
ENSG00000001461.16  NIPAL3  0.72    0.84    0.78    0.74

我想在B1与B1,B1与B2,B1与C1,B2与C2之间绘制散点图。

我使用了以下命令

df <- read.table(file="transformation.txt",header= TRUE,sep = "\t")
lapply(3:6,  function(X) ggscatter(df, x = "B1", y = colnames(df[X]), add = "reg.line", conf.int = TRUE, 
  cor.coef = TRUE, cor.method = "pearson",add.params = list(color="blue")))

我得到了4个地块。我想在1个地块中拥有所有4个地块。我该怎么办?

谢谢

1 个答案:

答案 0 :(得分:0)

您可能是这样说的吗?

library(GGally)
ggpairs(df[, -(1:2)])

enter image description here

GGally是一个非常不错的R程序包,它为绘图例程提供了许多自定义选项。


样本数据

df <- read.table(text =
    "tracking_id gene_short_name B1  B2  C1  C2
ENSG00000000003.14  TSPAN6  1.2 1.16    1.22    1.26
ENSG00000000419.12  DPM1    1.87    1.87    1.68    1.83
ENSG00000000457.13  SCYL3   0.59    0.63    0.82    0.69
ENSG00000000460.16  C1orf112    0.87    0.99    0.97    0.83
ENSG00000001036.13  FUCA2   1.59    1.59    1.4 1.39
ENSG00000001084.10  GCLC    1.43    1.55    1.46    1.32
ENSG00000001167.14  NFYA    1.2 1.3 1.39    1.21
ENSG00000001460.17  STPG1   0.43    0.46    0.34    0.76
ENSG00000001461.16  NIPAL3  0.72    0.84    0.78    0.74", header = T)