r - 调整 geom_point 大小以便绘制大值,但在 ggplot2 中不会显得更大?
问题描述
我遇到的问题是我希望高于某个阈值(=<25)的点不会产生大于设定比例的点。这些较大的点仍然需要显示,不能排除:
d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")
在上面的示例代码中,我有两个点的“覆盖率”大于 25+,并且在比例之外。我希望这些点的大小与 25+ 阈值相同。
解决方案
我想这就是你要找的:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
推荐阅读
- kubernetes - 当 Pod 在特定工作节点上调度时,它总是失败。如何调试它?
- node.js - 如果会话 cookie 在 maxAge 之后过期,尽管有用户活动,这不会影响用户体验吗?
- angular - 如何将 Angular Material Dialog 转换为普通组件?
- python - ModuleNotFoundError:没有名为“_pywrap_tensorflow_internal”的模块无法加载本机 TensorFlow 运行时
- ruby - 如何从 Ruby 中的哈希中删除特定值
- javascript - 如何让用户将电影添加到类似于 netflix 的列表中?
- linux - 带有 ubuntu 16.04 add-apt-repository 的 Docker 容器使用 groovy 而不是 xenial
- python - 是否可以将字符串转换为函数对象?
- sql - 查找两个表 BigQuery 之间最近的地理点
- sql - 我需要加入表和匹配参数