Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display only selected items in a ggplot2 legend? [duplicate]

Tags:

r

legend

ggplot2

I'm creating a stacked bar plot of relative abundance data, but I only want to display the ten most abundant organisms in the legend. How do I do this? I have no idea where to begin and haven't found any answers online.

Here's the plot with a full legend:

enter image description here

Thanks.

like image 691
RB88 Avatar asked Oct 31 '25 06:10

RB88


1 Answers

As pointed out by user20650 in the comments, the answer is to add a list of selected items to the breaks= argument in scale_fill_manual()

scale_fill_manual(breaks=list,values=colpal)

like image 55
RB88 Avatar answered Nov 03 '25 01:11

RB88



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!