-1

So I have a dataframe that I want to plot using gglot2 in R. To make you understand what I want Example =

  1. I have a table that has 5 columns A, B, C, D, E.
  2. I want to plot the graph of A vs B, A vs C, A vs D, A vs E.
  3. Finally I want to merge all these plots into one that will show the plot as A vs B, C, D, E.
  4. Also to note one of my dataframe column has values under 0.00x.... (here x = any number) upto 3 decimal place so I want to make sure the scaling is right.

Finally, thank you all for reading this and helping me out.

  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What have you tried? Where exactly are you getting stuck? Start with one problem at a time. – MrFlick Jul 01 '20 at 16:42
  • Check with `pairs()` – Duck Jul 01 '20 at 16:46
  • Also Check out `facet_wrap` and/or `facet_grid`: http://www.cookbook-r.com/Graphs/Facets_(ggplot2)/ – davidnortes Jul 01 '20 at 16:51

2 Answers2

0
library(grid)

library(ggplotify)

library(cowplot)

library(tidyverse)

Create all your plots (plot_1 to plot_n) e.g:

plot_1 <- ggplot(data, aes(x=x, y=y, fill=value)) + 
theme_classic() + 
theme(text = element_text(size=24), axis.text.x = element_text(angle=0, hjust=0.5), legend.position="none") +
geom_bar(stat="identity", color="black", position=position_dodge()) +
geom_errorbar(aes(ymin=lwr.ci, ymax=upr.ci), width=.2,position=position_dodge(.9)) + 
labs(y="ylab", x="xlab", subtitle = "subtitle") + scale_fill_manual(values=c("yellow", "blue"))

Then you put them in a simple plot as follows:

pdf("many_plots_in_one.pdf")

plot_grid(plot_1, plot_2, plot_3, plot_4, plot_5, plot_6, ncol=3, labels=LETTERS[1:6])

dev.off()
UseR10085
  • 7,120
  • 3
  • 24
  • 54
Batsi-2015
  • 43
  • 1
  • 6
0

You can make each plot separately. Then combine multiple plots together:

library(patchwork)

combined_plot <- plot_AvsB + plot_AvsC + plot_AvsD + plot_AvsE + plot_layout(ncol = 2)

combined_plot
Jeremy
  • 849
  • 6
  • 15