Skip to content

Bug sometimes with polygon geoms, filtered factors, drop = FALSE, and width = NULL  #5396

Closed

Description

@davidhodge931

Bugs only sometimes with polygon geoms, filtered factors, and drop = FALSE.

Always is fixed when width is not NULL.

Using ggplot2 3.4.3 (and also tested in 3.4.2)

library(tidyverse)

#filtered dataset
d <- diamonds |>
  filter(color %in% c("D", "H")) |>
  filter(cut %in% c("Ideal", "Good")) |>
  filter(clarity %in% c("VS1", "VS2"))

#example A
#doesn't works
d |>
  count(cut) |>
  ggplot() +
  geom_col(aes(x = n, y = cut)) +
  scale_y_discrete(drop = FALSE)

#works
d |>
  count(cut) |>
  ggplot() +
  geom_col(aes(x = n, y = cut), width = 0.9) +
  scale_y_discrete(drop = FALSE)

#works
d |>
  count(cut) |>
  ggplot() +
  geom_point(aes(x = n, y = cut)) +
  scale_y_discrete(drop = FALSE)

#doesn't work
d |>
  ggplot() +
  geom_violin(aes(x = price, y = cut)) +
  scale_y_discrete(drop = FALSE)

#works
d |>
  ggplot() +
  geom_violin(aes(x = price, y = cut), width = 0.9) +
  scale_y_discrete(drop = FALSE)

#example B
#doesn't works
d |>
  count(color) |>
  ggplot() +
  geom_col(aes(x = n, y = color)) +
  scale_y_discrete(drop = FALSE)

#example C
#works
d |>
  count(clarity) |>
  ggplot() +
  geom_col(aes(x = n, y = clarity)) +
  scale_y_discrete(drop = FALSE)

Created on 2023-08-23 with reprex v2.0.2

Activity

  1. changed the title [-]Bug _sometimes_ with polygon geoms, filtered factors, `drop = FALSE`, and `width = NULL` [/-] [+]Bug sometimes with polygon geoms, filtered factors, `drop = FALSE`, and `width = NULL` [/+] on Aug 23, 2023
  2. teunbrand commented on Aug 23, 2023

    @teunbrand
    Collaborator

    Some of these seem to already work in the development version of ggplot2. Only the violin case seems broken at the moment.

  3. added
    bug
    on Aug 23, 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

    buglayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions