在 ggridges 中,如何在不获得多个山脊的情况下对代码点进行着色?
In ggridges, how to colour code points without getting multiple ridges?
我试图通过索引(在本例中为 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")
Two ridges per group (but I want one)
如果我理解正确,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")
数据
由于问题不包含任何可重现的数据,我已尝试模拟 OP dataSet
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)
)
我试图通过索引(在本例中为 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")
Two ridges per group (but I want one)
如果我理解正确,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")
数据
由于问题不包含任何可重现的数据,我已尝试模拟 OP dataSet
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)
)