+1 vote
in Programming Languages by (37.8k points)
I am writing legends horizontally on a plot created using ggplot in R. How can I split the legends into two rows?

1 Answer

+2 votes
by (176k points)
selected by
 
Best answer

You can use the guides() function with color/fill as guide_legend() with parameter nrow=2. It will evenly split the legends into two rows.

When you have used the fill parameter of ggplot for the legends, use the following code:

guides(fill=guide_legend(nrow=2, byrow=TRUE))

When you have used the color parameter of ggplot for the legends, use the following code:

guides(color=guide_legend(nrow=2, byrow=TRUE))

Related questions

+3 votes
1 answer
+3 votes
1 answer
+1 vote
1 answer
+1 vote
1 answer
+5 votes
1 answer

...