0

I am trying to plot a scatter plot in R using ggscatter function from ggpubr package. I am showing you a subset of my data.frame

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

I want to make scatter plot between B1 vs B1, B1 vs B2, B1 vs C1, B2 vs C2.

I used the following command

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")))

I get individual 4 plots. I want to have all 4 plots in 1 plot. How can I do this?

Thanks

user3138373
  • 519
  • 1
  • 6
  • 18
  • Check out the `grid.arrange()` function in the `gridExtra` package or the `ggarrange()` function in the `ggpubr` package. This [link](http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page/) offers some examples. – DanY Aug 22 '18 at 21:52

1 Answers1

0

Do you perhaps mean something like this?

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

enter image description here

GGally is a very nice R package offering a lot of customisation options for its plotting routines.


Sample data

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)
Maurits Evers
  • 49,617
  • 4
  • 47
  • 68