Home > front end >  How to change orientation of each item in a ggplot2 legend?
How to change orientation of each item in a ggplot2 legend?

Time:02-08

enter image description here

enter image description here

The above shows 2 legends, one where each item is placed in a new column and one where each item is placed in a new row.

How can I control for that?

CodePudding user response:

This is controlled by the nrow and ncol arguments to guide_legend().

You can call guide_legend() either within guides():

plot   
  guides(color = guide_legend(nrow = 1))

…or within scale_*():

plot  
  scale_color_discrete(guide = guide_legend(nrow = 1))
  •  Tags:  
  • Related