0

大家好,我正在查看 R 中的一些山脊线图,更具体地说是在“ggridges 简介”一文中,我的目标是制作这个图但没有重叠:

library(ggplot2)
library(ggridges)
ggplot(iris, aes(x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5 - stat(ecdf)))) +
  stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
  scale_fill_viridis_c(name = "Tail probability", direction = -1)

通过阅读同一篇文章,可以添加重叠:

+ geom_density_ridges(scale = 0.9)

但由于某种原因,我收到了这个错误:

Error in 0.5 - ecdf : non-numeric argument to binary operator

谢谢

4

1 回答 1

0

要获得所需的结果,请去掉第二层geom_density_ridges(这会导致错误)并简单地添加scale = 0.9到第一层:

library(ggplot2)
library(ggridges)
ggplot(iris, aes(x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5 - stat(ecdf)))) +
  stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE, scale = 0.9) +
  scale_fill_viridis_c(name = "Tail probability", direction = -1)
#> Picking joint bandwidth of 0.181

于 2020-06-18T06:50:37.977 回答