gpt4 book ai didi

r - 将 geom_point 添加到 ggridges

转载 作者:行者123 更新时间:2023-12-04 09:34:42 26 4
gpt4 key购买 nike

如果我想为 ggridge 对象添加一个点估计,但我一直收到错误:

library(ggplot2)
library(ggridges)

iris_med <- iris %>% group_by(Species) %>% summarise(Sepal.Length = median(Sepal.Length))

ggplot(iris, aes(x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5-..ecdf..))) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
geom_point(aes(x = Sepal.Length, y = Species, color = "red"), data = iris_med)

Picking joint bandwidth of 0.181
Error in eval(expr, envir, enclos) : object 'ecdf' not found

我希望实现的输出: enter image description here

最佳答案

可以通过在geom_point 调用中指定inherit.aes = F 来解决问题:

ggplot(iris, aes(x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5-..ecdf..))) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
geom_point(aes(x = Sepal.Length, y = Species, color = "red"), data = iris_med, inherit.aes = F)

只产生以下信息:

选取 0.181 的联合带宽

enter image description here

编辑:另一种方法(感谢@Axeman 的评论)是将 fill 美学移动到 stat_density_ridges 层。

关于r - 将 geom_point 添加到 ggridges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50345984/

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