r - 在 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
如何将显示不同模型置信区间的矩形添加到图中?
解决方案
推荐阅读
- docker - 无法运行部署在 Docker 容器中的快速 API 应用程序
- snowflake-cloud-data-platform - 使用包含阿拉伯文本的数据行复制 S3 文件会导致记录结束并且复制失败
- json - 将查询结果转换为 json 对象
- spring - Spring + Hibernate:在更新条目时从存储库中选择
- python - 具有两个或更多输出的感知器
- typescript - 打字稿如何输出日志
- java - Hashtable - 获取索引之前的第一个元素
- javascript - 是否可以使用 workerpool 从网站获取?
- python - TypeError: 不支持的操作数类型 /: 'str' 和 'int' 仅适用于 KNN
- security - 如何使用 OAuth2 重定向错误来防止不良操作回火