Search code examples
rggplot2aestheticsgeom

Adding space between geom_pointrange()


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

Can anyone give me a hint? Thanks.


Solution

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