将geom_point添加到ggridges

时间:2018-05-15 08:50:44

标签: r ggplot2 ggridges

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

1 个答案:

答案 0 :(得分:3)

可以通过在> qde <- SPARQL(endpoint,query) Opening and ending tag mismatch: hr line 5 and body Opening and ending tag mismatch: body line 3 and html Premature end of data in tag html line 1 Error: 1: Opening and ending tag mismatch: hr line 5 and body 2: Opening and ending tag mismatch: body line 3 and html 3: Premature end of data in tag html line 1 调用中指定inherit.aes = F来解决问题:

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

enter image description here

编辑:另一种方法(感谢@ Axeman的评论)是将Picking joint bandwidth of 0.181审美移动到fill层。