I want to summary table next to the scatterplot in the final figure. The summary table should come next to the plot. Here is the sample code.
How can we do that?
Thanks
library(tidyverse)
library(cowplot)
# data
x <- runif(10000)
y <- runif(10000)
z <- c(rep(0, 5000), rep(1, 5000))
tbl <- tibble(x, y, z)
# plot
scatterplot <- ggplot(tbl,
aes(x = x,
y = y)) +
geom_point(alpha = 0.7,
size = 2) +
facet_grid(. ~ z) +
theme_bw() +
theme(aspect.ratio = 1) +
ggtitle("Scatter plot")
# add summary table
summary_tbl <- tbl %>%
group_by(z) %>%
summarise(count = n(),
x_mean = mean(x),
y_mean = mean(y))
# TASK
# to create a final plot with scatterplot and summary table in single row grid
plot_grid(scatterplot, summary_tbl,
nol = 2)

