eclarke / ggbeeswarm

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

Feature request: export Position ggproto classes and fallbacks for missing parameters #97

Open teunbrand opened 1 month ago

teunbrand commented 1 month ago

Hi there,

I think it could be convenient to export the PositionBeeswarm and PositionQuasirandom classes. This would make it convenient to use a simple position = "beeswarm" in a layer, rather than having to type out position = position_beeswarm() in full.

library(ggbeeswarm)
#> Loading required package: ggplot2

ggplot(mpg, aes(drv, displ)) +
  geom_point(position = "beeswarm")
#> Error in `geom_point()`:
#> ! Can't find position called "beeswarm".

# What it should look like
ggplot(mpg, aes(drv, displ)) +
  geom_point(position = position_beeswarm())

In addition to exporting the position classes, it would be nice if they have nice pre-populated parameters. In the example below, we cannot use position = "beeswarm" because there is no default method parameter.

# Simulate export of class
PositionBeeswarm <- ggbeeswarm:::PositionBeeswarm

ggplot(mpg, aes(drv, displ)) +
  geom_point(position = "beeswarm")
#> Error in `geom_point()`:
#> ! Problem while computing position.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `if (method %in% c("swarm", "compactswarm")) ...`:
#> ! argument is of length zero

Created on 2024-09-20 with reprex v2.1.1