ggplot2 Legend Key Columns

Hello, I am a new R user, still not familiar with the commands of R. In the picture attached, I followed what has been taught by the lecturer to come out with this chart. However, the legend took up too many space. I would like to know if there is any way to make the columns from three to one, so that all the keys will be only in one column.

Thank you in advance!

Hi, @agnes_zhiyea!

Welcome to R))
Yes, it is possible to make it one column. Add + guides(fill = guide_legend(ncol = 1)) to the code for your plot and it should solve your problem.

Hint, 99% of the questions regarding ggplot can be solved by simple googling. You, most likely, will find a solution in top 3 (sometimes top 1) of the googles return. For this instance I googled "ggplot legend one column" because I didn't remember exact command)

1 Like

@Dobrokhotov1989 Thank you so much! I have been googling them, but I guess I googled in a wrong way, resulting in nothing matches found. :sweat_smile:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.