0

How can I change the position of my legend in this arranged plot, so I get to visualize all the legend?

I have the following code:

plotCNAE_decils <- ggarrange(plotalimentacio_2021_decils, plottabac_2021_decils, plotvestit_2021_decils, plothabitatge_2021_decils, plotmobles_2021_decils, plotsalut_2021_decils,
                      plottransport_2021_decils, plotcomunicacions_2021_decils, plotoci_2021_decils, ploteducacio_2021_decils, plotrestaurants_2021_decils, plotaltres_2021_decils,
                       ncol=4, nrow=3, common.legend=TRUE, legend="bottom")
plotCNAE_decils

annotate_figure(plotCNAE_decils, 
                top=text_grob("Despesa monetària en els diferents grups CNAE, per decils de renda. Espanya (2021) \nEn euros i percentatge", size=15, face="bold", hjust=0, x=0.01, vjust=0.4),
                bottom=text_grob("Font: Elaboració pròpia a partir de dades de l'Enquesta de pressupostos familiars del 2021, base 2016, de l'INE.", hjust=0, x=1, face="italic", size=10))

enter image description here

Maria
  • 173
  • 7
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 24 '23 at 16:19
  • 1
    It looks like in your code you are combining 12 plots, not just 2; assuming that the plotting mechanism (aesthetics, etc) are all identical, I suggest it would be far easier to use `facet_wrap(~ year + source)` (or whatever the year/title columns are named) (optionally with `scales="free"`) on a single (combined?) dataset. This will ensure a well-positioned legend. – r2evans Jan 24 '23 at 16:29

0 Answers0