I was trying to do a multiplot with ggplot2
.
This was my initial code
nucmer_s1 <- ggarrange(eight_uniform, ten_uniform, twelve_uniform, fourteen_uniform, sixteen_uniform,
ncol=3, nrow=2, common.legend = TRUE, legend="bottom")
getting this error
Error in plot$scales : $ operator is invalid for atomic vectors
then.
annotate_figure(nucmer_s1,
top = text_grob("Genomas validados con distribución de datos equilibrada",
color = "black", face = "bold", size = 12))
however I obtain the graphic But I need to put a title in the each plot a title so I changed to this one
nucmer_s1 <-grid.arrange(
eight_uniform + ggtitle("8 genomas"),
ten_uniform + ggtitle("10 genomas"),
twelve_uniform + ggtitle("12 genomas"),
fourteen_uniform + ggtitle("14 genomas"),
sixteen_uniform + ggtitle("16 genomas"),
ncol=3, nrow=2, common.legend = TRUE, legend="bottom")
but I got
Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, :
only 'grobs' allowed in "gList"
Además: Warning messages:
1: In grob$wrapvp <- vp : Realizando coercion de LHD a una lista
2: In grob$wrapvp <- vp : Realizando coercion de LHD a una lista
so I erase the common.legend
part
and got this plot
Is there a way to put a title in each plot with the grey box without using
facet_grid
(cause I don't have that info in the data)? andIs there any way to put the legend in the blank side of a multi-plot?
Thank so much for your help
lemon
orcowplot
packages have really nice built-in functions to deal with shared legend between plotsexample from lemon package
example from cowplot package
Created on 2018-04-14 by the reprex package (v0.2.0).