I have a plot and a tabble, and I would like to put both into one plot with a footnote. And also how to align table to the left? and notation to the right?
My current codes are:
df<-structure(list(AEDECOD = c("Hypoxia", "Malignant pleural effusion",
"Decubitus ulcer", "Nausea"), ADY = c(13, 13, 13, 14)), row.names = c(NA,
-4L), class = "data.frame")
tbl <-structure(list(`Analysis Relative Day` = 13, `AE Type` = "SER",
`Adverse Event` = "Hypoxia/Malignant pleural effusion"), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
p1<- ggplot(data =df, aes(x = ADY, y = AEDECOD, color=AEDECOD))
geom_point()
tbl2<-tableGrob(tbl, rows=NULL)
p2 <-grid.arrange(p1, tbl2,
nrow = 2,as.table = TRUE,
bottom="Notation here")
print(p2)
My output looks like this:
CodePudding user response:
We could have more control by specifying the plot_layout
from patchwork
library(patchwork)
library(dplyr)
library(ggplot2)
library(gridExtra)
p2 <- tableGrob(tbl, rows=NULL)
p3 <- tableGrob("Notation here")
layout <- c(
area(t = 1, l = 1, b = 3, r = 5),
area(t = 4, l = 1, b = 7, r = 3),
area(t = 4, l = 6, b = 6, r = 7)
)
p1 p2 p3
plot_layout(design = layout)
NOTE: If we want to change the location, then we could make the changes in the value for t
op, b
ottom, l
eft, r
ight values in each of those plots - make sure that t < b
and l < r
-output