在ggridges中,如何在不获得多个脊线的情况下对点进行颜色编码?
我试图通过索引显示脊线图上的点(在ggridges中,如何在不获得多个脊线的情况下对点进行颜色编码?,r,ggplot2,ggridges,ridgeline-plot,R,Ggplot2,Ggridges,Ridgeline Plot,我试图通过索引显示脊线图上的点(PASS或FAIL)。但当我这样做的时候,我最终得到了每组两个脊。 我想知道如何每组只有一个山脊 我的代码,以及下面的输出图像: library(ggplot2) library(ggridges) library(scales) ggplot(dataSet, aes(x = `Vector_fails`, y = Group, fill = Group)) + geom_density_ridges(alpha = .1,
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希望为每个
组
绘制一条山脊线,而不管密码
。此外,应绘制点,但应使用密码
的值着色
一种可能的解决方案是绘制不带点的山脊线,然后添加第二层,在该层中绘制点,但使(然后复制的)山脊线不可见:
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的数据集
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)
)
nr您能否提供一个可复制的代码示例?见: