wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
704 stars 84 forks source link

Feature Request: Improve Error Reporting with Multiple Legends in get_legend #99

Closed billdenney closed 6 years ago

billdenney commented 6 years ago

The issue in the below code is that there is more than one legend rather than no legend. It would be helpful if that were specified by a different error. (I'm happy to make that simple pull request, if desired.)

library(cowplot)                                    
#> Loading required package: ggplot2
#> 
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:ggplot2':
#> 
#>     ggsave
p <-                                                
ggplot(data.frame(A=1:2), aes(x=A, y=A, colour=A)) +
geom_point()                                        
get_legend(plot_grid(p, p))                         
#> Error in get_legend(plot_grid(p, p)): Plot must contain a legend
clauswilke commented 6 years ago

This behavior is correct. Once you’re using plot_grid(), you’re de-facto dealing with a single plot without legend. There are no ggplot2 plots with multiple legends.

billdenney commented 6 years ago

Thanks for the clarification.