调整geom_point的大小,以便绘制较大的值,但在ggplot2中看起来不大吗? [英] Adjust geom_point size so large values are plotted, but do not appear larger in ggplot2?
本文介绍了调整geom_point的大小,以便绘制较大的值,但在ggplot2中看起来不大吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到的问题是,我希望高于某个阈值(=< 25)的点不会产生大于设置比例尺的点.这些较大的点仍需要显示,并且不能排除:
The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:
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+阈值相同.
In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.
推荐答案
我认为这是您要寻找的:
I think this is what you're looking for:
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")
这篇关于调整geom_point的大小,以便绘制较大的值,但在ggplot2中看起来不大吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文