Skip to content

ggbarstats returns error when variable has many levels #1015

@fkueck

Description

@fkueck

ggbarstats returns an error for factor variables with more levels than the palette vector. In previous versions, the plot was produced with a warning; now it fails with an error.
The following code returns the error "Error in vec_slice() at ggplot2/R/scale-.R:1330:5:
! Can't subset elements past the end.
ℹ Locations 10, 11, 12, …, 24, and 25 don't exist.
ℹ There are only 9 elements."

data("mtcars")
library("dplyr")
ggstatsplot::ggbarstats(mtcars %>% mutate(mpg = factor(mpg)),
                        "mpg",
                        "vs")

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