如何仅显示ggplot2图例中的选定项目? [英] How do I display only selected items in a ggplot2 legend?

查看:152
本文介绍了如何仅显示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:

谢谢。

推荐答案

正如所指出的那样user20650 ,答案是将所选项目的列表添加到 scale_fill_manual() breaks = 参数中

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)

scale_fill_manual(breaks=list,values=colpal)

这篇关于如何仅显示ggplot2图例中的选定项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆