我想绘制一个三列的条形图,其中两个箭头从一列开始到另外两列,并且这些箭头不相互重叠,如下所示。
我设法制作了图表,并使用geom_segment
s 来绘制箭头。但是,箭头从 column 开始时会重叠control
。
我以为我可以通过设置来解决这个问题geom_segment(..., position = position_nudge(x = 0.25))
。然而,这不仅改变了 的位置,x
也改变了xend
。那么,我应该如何稍微改变only 的geom_segment
位置x
,保持位置xend
不变?
MWE
library(tidyverse)
demoData <- tribble(
~priming, ~rt,
"control", 374,
"phonological", 267,
"orthographic", 304
) |>
mutate(
diff.from.baseline = rt - first(rt)
)
baseline <- demoData |>
filter(priming == "control") |>
dplyr::select(rt) |>
pull()
demoData |>
ggplot(
aes(
x = priming,
y = rt
)
) +
geom_col() +
#### from control to orthographic
geom_segment(
aes(
x = "control",
y = baseline,
xend = "control",
yend = baseline + 50
)#,
#position = position_dodge2(
# width = 0.5,
# preserve = "total"
# )
#position = position_nudge(
# x = 0.25,
# xend = 0
#)
) +
geom_segment(
aes(
x = "control" + 0.25,
y = baseline + 50,
xend = "orthographic",
yend = baseline + 50
)#,
#position = position_dodge2(
# width = 1,
# preserve = "total"
# )
#position = position_nudge(
# x = 0.25,
# xend = 0
#)
) +
geom_segment(
aes(
x = "orthographic",
y = baseline + 50,
xend = "orthographic",
yend = demoData |>
filter(priming == "orthographic") |>
dplyr::select(rt) |>
pull()
),
arrow = arrow()
) +
#### from control to phonological
geom_segment(
aes(
x = "control",
y = baseline,
xend = "control",
yend = baseline + 100
)
) +
geom_segment(
aes(
x = "control",
y = baseline + 100,
xend = "phonological",
yend = baseline + 100
)
) +
geom_segment(
aes(
x = "phonological",
y = baseline + 100,
xend = "phonological",
yend = demoData |>
filter(priming == "phonological") |>
dplyr::select(rt) |>
pull()
),
arrow = arrow()
)