Skip to content

Weird groups when using "fill" parameter #6790

@hejian41

Description

@hejian41

Hi, when using "fill" as an aesthetic, I encountered unexpected grouped boxplots or violin plots. The outputs were varied after executing the following codes each time:

ggplot(data = diamonds, mapping = aes(x = cut, y = price, fill = color)) +
geom_boxplot()

first executing:
Image

second executing:

Image

Also, it produces warning messages:

Warning message:
The following aesthetics were dropped during statistical transformation: fill.
i This can happen when ggplot fails to infer the correct grouping structure in the data.
i Did you forget to specify a group aesthetic or to convert a numerical variable into a factor?

However, it would be fine if I subset the top 8000 rows.

ggplot(data = diamonds[1:8000,], mapping = aes(x = cut, y = price, fill = color)) +
geom_violin()

Image

_sessionInfo()

R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libmkl_rt.so; LAPACK version 3.8.0

locale:
[1] C

time zone: Asia/Shanghai
tzcode source: system (glibc)

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] lubridate_1.9.4 forcats_1.0.1 stringr_1.6.0 dplyr_1.1.4 purrr_1.1.0 readr_2.1.5 tidyr_1.3.1 tibble_3.3.0 tidyverse_2.0.0 ggpubr_0.6.2 ggplot2_4.0.1

loaded via a namespace (and not attached):
[1] generics_0.1.4 rstatix_0.7.2 stringi_1.8.7 hms_1.1.4 digest_0.6.39 magrittr_2.0.4 timechange_0.3.0 evaluate_1.0.5 grid_4.5.2
[10] RColorBrewer_1.1-3 fastmap_1.2.0 backports_1.5.0 Formula_1.2-5 scales_1.4.0 abind_1.4-8 cli_3.6.5 rlang_1.1.6 pak_0.9.0
[19] withr_3.0.2 yaml_2.3.10 tools_4.5.2 tzdb_0.5.0 ggsignif_0.6.4 broom_1.0.11 vctrs_0.6.5 R6_2.6.1 lifecycle_1.0.4
[28] car_3.1-3 pkgconfig_2.0.3 pillar_1.11.0 gtable_0.3.6 glue_1.8.0 xfun_0.54 tidyselect_1.2.1 rstudioapi_0.17.1 knitr_1.50
[37] farver_2.1.2 htmltools_0.5.9 rmarkdown_2.29 carData_3.0-5 labeling_0.4.3 compiler_4.5.2 S7_0.2.1_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions