eclarke / ggbeeswarm

Column scatter / beeswarm-style plots in ggplot2
GNU General Public License v3.0
539 stars 31 forks source link

Transform `xend` to support use in `geom_segment` #89

Closed krassowski closed 6 months ago

krassowski commented 1 year ago

This restores the ability to use position_quasirandom in geom_segment, geom_curve and friends (see https://github.com/eclarke/ggbeeswarm/issues/55).

Before After
image image
library(ggplot2)
mpg$after2000 = mpg$year > 2000
data = aggregate(
    hwy ~ manufacturer + model + after2000 + drv,
    mpg,
    mean
)
(
    ggplot(data, aes(x=after2000, y=hwy))
    + geom_violin()
    + geom_segment(
       data=unstack(data, hwy ~ after2000),
       aes(x=FALSE, xend=TRUE, y=FALSE., yend=TRUE.),
       color='grey',
       position=ggbeeswarm::position_quasirandom()
    )
    + ggbeeswarm::geom_quasirandom(aes(color=drv))
    + scale_color_discrete(
        labels=c(
            'f'='front-wheel drive',
            'r'='rear-wheel drive',
            '4'='four-weel drive'
        ),
        name='the type of drive train'
    )
    + ylab('highway miles per gallon')
    + theme_bw()
)
roaldarbol commented 6 months ago

This would be super useful! Would it be possible to review it soon and hopefully merge?

eclarke commented 6 months ago

Yeah, I'll review this today. Thanks for boosting