3

如果我想向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

我希望实现的输出: 在此处输入图像描述

4

1 回答 1

3

该问题可以通过inherit.aes = Fgeom_point调用中指定来解决:

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)

只产生以下消息:

Picking joint bandwidth of 0.181

在此处输入图像描述

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

于 2018-05-15T08:58:24.740 回答