我有一个相当复杂的图表(至少对我来说),我想为重要的比较添加星号。我已经在我的数据框的单独列中编码了重要的比较。这是我的数据:
data = structure(list(mask = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L), .Label = c("roi1", "roi2", "roi3", "roi4"), class = "factor"),
comp = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L,
3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L), .Label = c("comp1",
"comp2", "comp3"), class = "factor"), type = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("rand", "real"
), class = "factor"), dv = c(0.5001, 0.5002, 0.5001, 0.5002,
0.5002, 0.7658, 0.5, 0.8692, 0.4998, 0.8568, 0.5001, 0.8814,
0.5001, 0.5002, 0.5003, 0.5001, 0.5, 0.6943, 0.5003, 0.669,
0.5, 0.6205, 0.5001, 0.686), std = c(0.0258, 0.0351, 0.0351,
0.0258, 0.0258, 0.0347, 0.0346, 0.0256, 0.0347, 0.0254, 0.0239,
0.0351, 0.0351, 0.0347, 0.0256, 0.0347, 0.0256, 0.0258, 0.0348,
0.0256, 0.0351, 0.0254, 0.0254, 0.0347), sig = c(0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 1L, 0L, 1L, 0L, 1L)), class = "data.frame", row.names = c(NA,
-24L))
head(data)
mask comp type dv std sig
1 roi1 comp1 rand 0.5001 0.0258 0
2 roi1 comp1 real 0.5002 0.0351 0
3 roi1 comp2 rand 0.5001 0.0351 0
4 roi1 comp2 real 0.5002 0.0258 0
5 roi1 comp3 rand 0.5002 0.0258 0
6 roi1 comp3 real 0.7658 0.0347 1
这是我的图表的代码:
ggplot(data=data, aes(x=comp, y=dv, fill=type)) +
geom_bar(stat="identity", position=position_dodge()) +
theme_bw() + facet_wrap(. ~ mask, ncol=2) +
scale_y_continuous(name = "accuracy", limits = c(0, 1)) +
geom_errorbar(aes(ymin=dv-std, ymax=dv+std), width=.2,
position=position_dodge(.9))
但是,我想在相应的实数行在 sig 列中为 1 的条形之间添加一个星号,例如在 roi1 comp3 rand 和 real 之间。完成的图表应如下所示:
有谁知道如何做到这一点?
干杯,马克斯

