0

我试图通过索引(PASSFAIL在本例中)在我的山脊图上显示点。但是当我这样做时,我最终每组有两个山脊。我想知道如何每组只有一个山脊?

我的代码,以及下面的输出图像:

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")

每组两个山脊(但我想要一个)

在此处输入图像描述

4

1 回答 1

0

如果我理解正确,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)
)
于 2020-01-26T18:03:07.273 回答