Skip to content

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

@teunbrand

Description

@teunbrand

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions