r - 从ggplot中删除某些数据
问题描述
我正在按年份绘制物种丰度(计数)图,每个物种都有不同的颜色。我试图摆脱一些没有数据或数据微不足道的物种。到目前为止,我有这个:
ggplot(data = df, mapping = aes(x = Year, y = Count,
color = Species)) + geom_line()
该图正是我想要的,但我不知道如何从图中删除一个物种的数据,所以它看起来更干净一些。
这是数据的样子:
Year Species Count
1 1992 American Toad 2
2 1993 American Toad 12
3 1994 American Toad 13
4 1995 American Toad 120
5 1996 American Toad 144
6 1997 American Toad 82
解决方案
正如评论中所建议的,您可以使用它dplyr
来filter
输出行:
library(dplyr)
library(ggplot2)
df %>%
filter(Species != "unwanted species") %>%
ggplot(mapping = aes(x = Year, y = Count, color = Species)) +
geom_line()
推荐阅读
- regex - 在使用正则表达式 SPIP -> WordPress(重定向插件)重定向时需要帮助
- facebook - 无法从 facebook api 获取报告,状态为 400,错误代码为 2601
- javascript - 请从 Exploring ES6 中删除这个示例
- maven - Spring Boot 应用配置文件依赖的数据源
- java - 使用 Retrofit 访问 recyclerview 适配器中的嵌套 JSON 数据
- jquery - fullpage.js 在 reBuild() 之后删除事件侦听器
- javascript - Highstock.js 问题:如何仅针对当天数据绘制 VWAP 指标?
- tensorflow - 同时训练判别器和生成器(Tensorflow)
- javascript - 如何将 HTML(联系人)表单的(消息字段)数据发送到特定的电子邮件地址?
- c# - ASP.NET Core 的输入标记助手不会将其文本更改为绑定模型字段