- R Data Visualization Recipes
- Vitor Bianchi Lanzetta
- 48字
- 2021-07-02 23:33:29
Getting ready
Package gridExtra must be installed:
> if( !require(gridExtra)){ install.packages('gridExtra')}
The recipe also requires a function to withdraw the legends from the plots:
> g_legend <- function(p){
> tmp <- ggplot_gtable(ggplot_build(p))
> leg <- which(sapply(tmp$grobs, function(x) x$name) == 'guide-box')
> legend <- tmp$grobs[[leg]]
> return(legend)}
This later solution was found as a StackOverFlow answer given by Luciano Selzer. Now we're ready for action.