0

I have plotted different graphs in my R-Script with the help of ggplot. To compare them I need to integrate them into one graph.

this is my current code for the single graphs:

p1 <- ggplot(merch42, aes(x = day_code, y = avg_logistic_review_score, col = "red"))+   
  geom_smooth(method = "loess", span = 1/25, col = "red")

p2 <- ggplot(merch323, aes(x = day_code, y = avg_logistic_review_score, col = "blue"))+
  geom_smooth(method = "loess", span = 1/25, col = "blue")

p3 <- ggplot(merch24, aes(x = day_code, y = avg_logistic_review_score, col = "green"))+
  geom_smooth(method = "loess", span = 1/25, col = "green")

p4 <- ggplot(merch180, aes(x = day_code, y = avg_logistic_review_score, col = "yellow"))+
  geom_smooth(method = "loess", span = 1/25, col = "yellow")

p5 <- ggplot(merch505, aes(x = day_code, y = avg_logistic_review_score, col = "merch505"))+
  geom_smooth(method = "loess", span = 1/25, col = "black")

Has someone an idee how this works? thanks very much:) Phil

Prradep
  • 5,506
  • 5
  • 43
  • 84
Phil R
  • 1
  • Thanks very much for fast answers. Your linked older questions, just shows how i could arrange all graphs nextto each other. What I'm looking forward to do, is to build one coordinate system, in which i can see all four graphs:) – Phil R Apr 25 '18 at 13:48
  • Merge your data in one dataframe with grouping column. Then use facets, `ggplot(mtcars, aes(mpg, disp)) + geom_smooth() + facet_grid(.~gear)` or colour to show grouping, e.g.: `ggplot(mtcars, aes(mpg, disp, col = as.factor(gear))) + geom_smooth()` – zx8754 Apr 25 '18 at 20:46

1 Answers1

0

Use the function grid.arrange() from the library, gridExtra. A minimum reprex is given below;

library(ggplot2)
library(gridExtra)

p1 <- qplot(mpg, wt, data = mtcars, colour = cyl)
p2 <- qplot(mpg, data = mtcars) + ggtitle("title")
p3 <- qplot(mpg, data = mtcars, geom = "dotplot")
p4 <-
  p1 + facet_wrap( ~ carb, nrow = 1) + theme(legend.position = "none") +
  ggtitle("facetted plot")

# grid.arrange(p1, p2, nrow = 1)
grid.arrange(p1, p2, p3, p4, nrow = 2, ncol=2)

mutipleplots_on_a_page

mnm
  • 1,962
  • 4
  • 19
  • 46