在 stat_density_ridges 上覆盖 gom_rect 或 geom_tile

问题描述

我使用 stat_density_ridges 制作了一个山脊线图,我想在顶部覆盖一个矩形。我曾尝试使用 geom_rect 和 geom_tile 来做到这一点,但我无法让它工作。这是我当前的代码

rm(list=ls(all=TRUE)); cat('\014') # clear workspace
library(tidyverse)
library(ggplot2)
library(viridis) 
library(rstatix)

data(iris)
iris$treatment <- rep(c("A","B","C"),length(iris$Species)/3)
mydf <- gather(iris,Variable,value,Sepal.Length:Petal.Width)

ggplot()+
  geom_tile(aes(x=1,y = 1,width =  1,height = 10),fill = "light blue",alpha = 1)+
  stat_density_ridges(data= mydf,aes(x= value,y = Species,fill = factor(stat(quantile))),geom = "density_ridges_gradient",calc_ecdf = TRUE,quantiles = c(0.1,0.9),scale = 1) +
  scale_fill_manual(
    name = "Probability",values = c("#FF0000A0","light grey","#0000FFA0"),labels = c("(0,0.1]","(0.1,0.9]","(0.9,1]"))+
  coord_cartesian(xlim=c(-10,10))+
  theme_bw()+
  facet_wrap(~Variable,ncol = 1)

包含 geom_tile 行,它返回此错误Error: discrete value supplied to continuous scale 如何在图中添加一个显示不同模型置信区间的矩形?

删除那条线后,我得到以下图像。

With that line removed,i get the attatched image.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)