-
Notifications
You must be signed in to change notification settings - Fork 2.1k
stat_bin()
calculates wrong numbers when a geom_col()
with custom data
is present
#5829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report! It seems that the computation of the bins do not match among the two layers. I'd just use library(ggplot2)
faithful |>
ggplot(aes(x = eruptions)) +
geom_histogram(
aes(width = after_stat(0.9 * width)),
bins = 30,
binwidth = NULL,
center = NULL,
boundary = 4,
closed = "right"
) +
geom_text(
mapping = aes(
y = after_stat(count),
label = after_stat(count)
),
stat = "bin",
bins = 30,
binwidth = NULL,
center = NULL,
boundary = 4,
closed = "right"
)
#> Warning in geom_histogram(aes(width = after_stat(0.9 * width)), bins = 30, :
#> Ignoring unknown aesthetics: width Created on 2024-04-06 with reprex v2.1.0 |
Yeah I can confirm that the warning would be fixed by #5807, so you woun't need to circumvent |
I agree that setting |
I think the interaction is due to that the bin breaks calculation in the text layer is based on the x-axis range of the plot as a whole. The range of |
Uh oh!
There was an error while loading. Please reload this page.
In an attempt to create a bar plot while binning data, I have stumbled across a surprising interaction between
geom_col()
andgeom_text()
.The following code is supposed to do two things:
geom_col()
by calculatingdata
on my owngeom_text()
by usingstat_bin()
to calculate the dataHowever, this leads to suprising behavior in two regards:
stat_bin()
are off.geom_col()
is commented out.Is this somehow correct behavior or a bug?
Using ggplot2 3.5.0 with R 4.3.3
(Why create the graph above like that in the first place? I deliberately want to avoid
geom_histogram()
because the count bars are not supposed to touch each other, hencegeom_col()
.)The text was updated successfully, but these errors were encountered: