Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Arranging several ggplots in same window

I have created below ggplots in same window

library(ggplot2)
library(patchwork)

x <- seq(0.01, .99, length.out = 100)
df <- data.frame(
  x = rep(x, 2),
  y = c(qlogis(x), 2 * qlogis(x)),
  group = rep(c("a","b"),
  each = 100)
)
p1 <- ggplot(df, aes(x=x, y=y, group=group))
p2 <- ggplot(df, aes(x=x, y=y, group=group))
p3 <- ggplot(df, aes(x=x, y=y, group=group))
p4 <- ggplot(df, aes(x=x, y=y, group=group))
wrap_plots(A = p1, B = p2, C = p4, design = "AABB\n#CC#")

These generated below plot window

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However now, I also want to squeeze my 3rd ggplot p3 within the bottom-left white-space in the same window, without disturbing current structure.

Is there any way to achieve this. Any pointer will be very help.

>Solution :

Does this approach solve your problem?

library(tidyverse)
library(patchwork)

x <- seq(0.01, .99, length.out = 100)
df <- data.frame(
  x = rep(x, 2),
  y = c(qlogis(x), 2 * qlogis(x)),
  group = rep(c("a","b"),
              each = 100)
)
p1 <- ggplot(df, aes(x=x, y=y, group=group))
p2 <- ggplot(df, aes(x=x, y=y, group=group))
p3 <- ggplot(df, aes(x=x, y=y, group=group))
p4 <- ggplot(df, aes(x=x, y=y, group=group))

layout <- "
AAABBB
CDDD##
"
p1 + p2 + p3 + p4 + 
  plot_layout(design = layout)

Created on 2022-08-22 by the reprex package (v2.0.1)


Or perhaps:

library(tidyverse)
library(patchwork)

x <- seq(0.01, .99, length.out = 100)
df <- data.frame(
  x = rep(x, 2),
  y = c(qlogis(x), 2 * qlogis(x)),
  group = rep(c("a","b"),
              each = 100)
)
p1 <- ggplot(df, aes(x=x, y=y, group=group))
p2 <- ggplot(df, aes(x=x, y=y, group=group))
p3 <- ggplot(df, aes(x=x, y=y, group=group))
p4 <- ggplot(df, aes(x=x, y=y, group=group))

layout <- "
AAABBB
AAABBB
CDDD##
#DDD##
"
p1 + p2 + p3 + p4 + 
  plot_layout(design = layout)

Created on 2022-08-22 by the reprex package (v2.0.1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading