如何解决在 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
如何在图中添加一个显示不同模型置信区间的矩形?
删除那条线后,我得到以下图像。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。