我想将垂直线段添加到直方图显示自定义分位数的山脊线图中。
如果我用..x..
. 但我想在密度图中显示分位数。我写了以下代码:
library(datasets)
library(ggplot2)
data("iris")
iris_lines <- data.frame(Species = c("setosa", "versicolor", "virginica"),
x0 = c(5, 5.9, 6.5))
Figure1 <- ggplot(iris, aes(x=Sepal.Length, y=Species, fill=(..quantile..))) +
geom_density_ridges_gradient(jittered_points = FALSE, calc_ecdf = TRUE, quantile_lines = c(TRUE), quantiles =c(0.1,0.25,0.75,0.9),scale=0.9, color='white')+
geom_segment(data = iris_lines, aes(x = x0, xend = x0, y = as.numeric(Species), yend = as.numeric(Species) + c(.9,.5,.5)), color = "red") + scale_y_discrete(expand = c(0.01, 0))
Figure1
如果我映射填充颜色,则代码有效,因为fill = ..x..
我得到代表每个密度图平均值的三条垂直线;但是,如果我在fill = ..quantile..
得到以下错误时映射填充颜色:
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 1, 3