r - 在ggridges中,如何在没有多个脊的情况下为代码点着色?
问题描述
我试图通过索引(PASS
或FAIL
在本例中)在我的山脊图上显示点。但是当我这样做时,我最终每组有两个山脊。我想知道如何每组只有一个山脊?
我的代码,以及下面的输出图像:
library(ggplot2)
library(ggridges)
library(scales)
ggplot(dataSet, aes(x = `Vector_fails`, y = Group, fill = Group)) +
geom_density_ridges(alpha = .1,
point_alpha = 1,
jittered_points = TRUE,
aes(point_color = PassCode)) +
labs(title = 'Vector_fails') +
scale_x_log10(limits = c(0.09, 1000000),
breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
annotation_logticks(sides="b")
解决方案
如果我理解正确,OP 想要为每个绘制一条山脊线,Group
而不管PassCode
. 此外,这些点应该被绘制出来,但用 的值着色PassCode
。
一种可能的解决方案是绘制没有点的山脊线,然后在绘制点的位置添加第二层,但(然后复制的)山脊线已变得不可见:
library(ggplot2)
library(ggridges)
library(scales)
ggplot(dataSet, aes(x = `Vector_fails`, y = Group, fill = Group)) +
geom_density_ridges(alpha = .1) + # plot rigdelines without points
geom_density_ridges(alpha = 0, # plot points with invisible ridgelines
color = NA,
jittered_points = TRUE,
point_alpha = 1,
aes(point_color = PassCode)) +
labs(title = 'Vector_fails') +
scale_x_log10(limits = c(0.09, 1000000),
breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
annotation_logticks(sides="b")
数据
由于问题不包括任何可重现的数据,我试图模拟 OPdataSet
nr <- 1000L
set.seed(1L)
dataSet <- data.frame(
Vector_fails = sample(9L, nr, TRUE) * 10^sample(c(0:1, 4:5), nr, TRUE),
Group = sample(c("Normal", "Trial 1", "Trial 2"), nr, TRUE, prob = c(0.8, 0.1, 0.1)),
PassCode = sample(c("PASS", "FAIL"), nr, TRUE)
)
推荐阅读
- javascript - 检查按下的按钮是否使用 PLAYWRIGHT 重定向到正确的页面?
- graphql - 除了列表查询之外,GraphQL 还应该提供单项查询吗?
- kubernetes-helm - 由于安全上下文错误,Helm 在 openshift 中失败
- iis - Telerik:未捕获的 TypeError:无法读取 null 的属性(读取“值”)
- php - jQuery load() 无法加载带有文本文件的 php 页面?
- flutter - 颤振 BlocProvider 导航
- ios - 我该如何解决致命错误:找不到模块'package_name'
- c# - SQL DataReader 到数组中
- python - 合并不同大小的数据框并绘制列的差异
- r - 重现使用 R 进行卡方检验的过程