Closed
Description
I found a potential problem with the widths of bars using geom_bar
when using factor levels, and keeping unused levels with drop = F
argument in scale_x_discrete
. This can be overcome by setting the width
in aesthetic but thought the variable nature of widths in plotting might be an issue.
Here is the code to reproduce the bug:
library(ggplot2)
df <- data.frame(
x = factor(c('A', 'D'), levels = LETTERS[1:5])
)
ggplot(df, aes(x)) +
geom_bar() +
scale_x_discrete(drop = F)
df <- data.frame(
x = factor(c('B', 'D'), levels = LETTERS[1:5])
)
ggplot(df, aes(x)) +
geom_bar() +
scale_x_discrete(drop = F)
Created on 2023-02-28 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels