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

how to put a plot and a table together using grid.arrange

I have a plot and a table, and I would like to combine them into a plot. how should I do that.

Here is my codes:

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))+ geom_point()
p2 <-grid.arrange(p1, tbl,
nrow = 2,as.table = TRUE)

print(p2)

I got the error codes:

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

Error: Input must be a vector, not a <viewport> object.

If you know any other way to do the same thing, I would like to learn that as well.

>Solution :

We may use ggarrange after converting the tibble to ggtexttable

library(ggpubr)
ggarrange(p1, ggtexttable(tbl), nrow = 2)

Or using the OP’s code

library(gridExtra)
grid.arrange(p1, ggtexttable(tbl),
      nrow = 2,as.table = TRUE)

-output

enter image description here

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