gpt4 book ai didi

r - 调整 geom_point 大小以便绘制大值,但在 ggplot2 中不会显得更大?

转载 作者:行者123 更新时间:2023-12-04 02:53:23 25 4
gpt4 key购买 nike

我遇到的问题是我希望高于某个阈值 (=<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+ 阈值相同。

Example Plot output

最佳答案

我想这就是您要找的:

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")

Picture of Truncated Coverage

关于r - 调整 geom_point 大小以便绘制大值,但在 ggplot2 中不会显得更大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54013902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com