I am trying to place two boxplots (box1, box2) beside each other and to label them "A" and "B" in the upper left corner. I am trying to use the cowplot
-package for this.
This is the function:
plot_grid(box1, box2, labels = c('A', 'B'), label_size = 12)
Then I get the warning message:
In as_grob.default(plot) : Cannot convert object of class list into a grob.*
And the only printout I get is the A and B letters. I have also tried to use:
boxC <- c(box1, bow2)
plot_grid(plotlist = boxC, labels = c('A', 'B'), label_size = 12, nrow=2)
My code mostly came from the answers to this similar question, but it does not seem to work for me.
Lay out multiple ggplot graphs on a page
In that question someone also suggested using dev.off()
but that did not work for me either.
So grateful for replies!
The solution that I wrote based on mhh's reply:
BOX1_data <- read.table(file = "clipboard",
sep = "\t", header=TRUE)
BOX1_data$Histology <- as.factor(BOX1_data$Histology)
BOX1plot <- ggplot(BOX1_data, aes(x=Histology, y=No.Variants)) + geom_boxplot()
BOX1plot
BOX2_data <- read.table(file = "clipboard",
sep = "\t", header=TRUE)
BOX2_data$Stage <- as.factor(BOX2_data$Stage)
BOX2plot <- ggplot(BOX2_data, aes(x=Stage, y=No.Variants)) + geom_boxplot()
BOX2plot
BOX_list <- list(BOX1plot, BOX2plot)
> ggarrange(plotlist = BOX_list, labels = c('A', 'B'), ncol = 2)