Florian
Florian

Reputation: 1258

Align ggplot objects within ggarange

I would like to align a ggtexttable {ggpubr} and a graphic {ggplot} by ggarrange {ggpubr} on the left side of the plot.

enter image description here

Is there a way to do this?

I tried the align argument but the objects are still centered

library(ggpubr)
library(ggplot2)
library(tidyverse)

df <- tibble(Col1 = 1:3,
         Col2 = rnorm(3))

plot <- df %>% 
  ggplot(aes(x = Col1,
         y = Col2)) + 
  geom_line()

table <- ggtexttable(df,
                     rows = NULL)

ggarrange(plot, table,
          ncol = 1, nrow = 2,
          heights = c(1, 0.5))

Upvotes: 2

Views: 1063

Answers (1)

Tung
Tung

Reputation: 28371

There are several packages you can try. See more here

library(tidyverse)
library(ggpubr)

df <- tibble(Col1 = 1:3,
             Col2 = rnorm(3))

plot1 <- df %>% 
  ggplot(aes(x = Col1,
             y = Col2)) + 
  geom_line()

table1 <- ggtexttable(df,
                     rows = NULL)


library(cowplot)
bottom <- plot_grid(table1, NULL, NULL, NULL)
plot_grid(plot1, bottom, 
          nrow = 2)

library(patchwork)
plot1 / (table1 | plot_spacer() | plot_spacer() |  plot_spacer())

library(magrittr)
library(multipanelfigure)
figure1 <- multi_panel_figure(columns = 3, rows = 2, panel_label_type = c("none"))

figure1 %<>%
  fill_panel(plot1, column = 1:3, row = 1) %<>%
  fill_panel(table1, column = 1, row = 2) %<>%
  fill_panel(plot_spacer(), column = 2, row = 2) %<>%
  fill_panel(plot_spacer(), column = 3, row = 2)
figure1

Created on 2019-02-19 by the reprex package (v0.2.1.9000)

Upvotes: 3

Related Questions