Skip to content

Dropped cases are taken into account for the dodging of geom_boxplot but not geom_violin #5002

Closed

Description

@JacobElder

Dropped cases are taken into account for dropped groups are still taken into account for the dodging of geom_boxplot but not geom_violin

The issue is detailed with reproducible code, a diagnosis, and solution from a commenter on StackOverflow. It appears there may be an inconsistency between geom_violinn and geom_boxplot.

https://stackoverflow.com/questions/73900036/boxplot-and-violin-plot-misaligned-in-ggplot2-for-only-one-level-of-the-x-axis/73900343#73900343

Activity

  1. changed the title [-]Dropped cases are taken into account for dropped groups are still taken into account for the dodging of geom_boxplot but not geom_violin[/-] [+]Dropped cases are taken into account for the dodging of geom_boxplot but not geom_violin[/+] on Sep 29, 2022
  2. teunbrand commented on Jan 4, 2023

    @teunbrand
    Collaborator

    Here is a slightly more minimal reprex:

    library(ggplot2)
    
    df <- data.frame(
      x = factor(rep(1:2, each = 4)),
      y = rep(1:2, 4),
      g = rep(c("A", "A", "B", 'B'), 2)
    )
    
    p <- ggplot(df, aes(x, y, fill = g)) +
      geom_violin(position = position_dodge(0.9)) +
      geom_boxplot(position = position_dodge(0.9))
    
    p %+% head(df, -1)
    #> Warning: Groups with fewer than two data points have been dropped.

    Created on 2023-01-04 by the reprex package (v2.0.1)

  3. added
    bug
    on Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions