你可能会用 cut
ggplot(mtcars, aes(x = as.factor(cyl))) +
geom_bar(aes(fill = cut(stat(count), breaks = c(0, 8, 12, Inf)))) +
labs(fill = "Breaks")
您显然需要根据需要/数据调整休息时间。
编辑
如果使用geom_col
而不是,geom_bar
则需要更改fill = stat(count)
为fill = value_column
(无论value_column
是什么,但都应与我们映射到的相同y
)。
例:
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
ggplot(df, aes(trt, outcome)) +
geom_col(aes(fill = cut(outcome, breaks = c(0, 2, 3, Inf)))) +
labs(fill = "Breaks")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句