0

I just can't figure out how to add space between two geom_pointrange(s)().

Can anyone give me a hint? Thanks.

  • 1
    A little tricky without seeing the structure of your data.frame `df`. Perhaps you could look into combining your `df` and `dfcontrol` into a single dataframe (e.g. using `rbind`) with a third variable like `type` where `df$type <- "exp"` and `dfcontrol$type <- "control"`. Then use `group = type` in your ggplot `aes` with `position_dodge()` – krfurlong Oct 13 '22 at 15:10

1 Answers1

0

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 ggplotting.