I'm replicating a figure and I'm very close to hitting home. But I just can't figure out how to add space between two geom_pointrange(s)().
This is my figure: https://i.postimg.cc/3xNt19Lp/vv.png
This is the figure I'm replicating: https://i.postimg.cc/DwGX7X0H/plot.png
Can anyone give me a hint? Thanks.
This is the code I have used to make my plot:
ggplot(NULL, aes(expcondition, coefs))
geom_pointrange(data = df, aes(ymax=coefs 1.645standarderror, ymin=coefs-1.645standarderror), size=1.5)
geom_pointrange(data = df, aes(ymax=coefs 1.96standarderror, ymin=coefs-1.96standarderror), size=0.9)
geom_pointrange(data = dfcontrol, aes(ymax=coefs 1.645standarderrorC, ymin=coefs -1.645standarderrorC), size=1.5, color = "grey")
geom_pointrange(data = dfcontrol, aes(ymax=coefs 1.96standarderrorC, ymin=coefs-1.96standarderrorC), size=0.9, color = "grey")
CodePudding user response:
position_nudge
does the trick. Using some dummy data:
data.frame(expcondition = c('A', 'B'),
coefs = 6:7) %>%
ggplot(aes(expcondition, coefs))
geom_pointrange(aes(ymin = coefs * .9, ymax = coefs * 1.2))
geom_pointrange(aes(ymin = coefs * .8, ymax = coefs * 1.1), col = 'grey',
## add some horizontal shift:
position = position_nudge(x = .1)
)
aside: as user krfurlong suggested, merging and pivoting your data into long format often helps with wrangling your data, not only for ggplot
ting.