-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Documentation for plotting bin proportion in geom_histogram #3522
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
Hmm... I'm wondering if using library(ggplot2)
ggplot(data.frame(x = 1, id = factor(1:3)), aes(x, x)) +
geom_text(aes(label = stat(PANEL)), size = 20) +
facet_wrap(vars(id)) Created on 2019-09-11 by the reprex package (v0.3.0) In my opinion, @clauswilke |
I'm not sure I understand what "it's not a calculated variable of These are all the variables that Lines 168 to 175 in 7f317d4
I don't see how width is in any way different than, say, density .
|
Yes,
library(ggplot2)
p <- ggplot(diamonds, aes(carat)) +
geom_histogram()
head(layer_data(p))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> y count x xmin xmax density ncount
#> 1 573 573 0.1658621 0.08293103 0.2487931 0.06404668 0.03769737
#> 2 15200 15200 0.3317241 0.24879310 0.4146552 1.69896944 1.00000000
#> 3 8165 8165 0.4975862 0.41465517 0.5805172 0.91263720 0.53717105
#> 4 6096 6096 0.6634483 0.58051724 0.7463793 0.68137617 0.40105263
#> 5 4138 4138 0.8293103 0.74637931 0.9122414 0.46252208 0.27223684
#> 6 7465 7465 0.9951724 0.91224138 1.0781034 0.83439519 0.49111842
#> ndensity PANEL group ymin ymax colour fill size linetype alpha
#> 1 0.03769737 1 -1 0 573 NA grey35 0.5 1 NA
#> 2 1.00000000 1 -1 0 15200 NA grey35 0.5 1 NA
#> 3 0.53717105 1 -1 0 8165 NA grey35 0.5 1 NA
#> 4 0.40105263 1 -1 0 6096 NA grey35 0.5 1 NA
#> 5 0.27223684 1 -1 0 4138 NA grey35 0.5 1 NA
#> 6 0.49111842 1 -1 0 7465 NA grey35 0.5 1 NA Created on 2019-09-12 by the reprex package (v0.3.0) But, I don't check this in detail yet. Maybe I'm just confused with the case of |
Weird, I have no idea why |
IIRC, this is somewhat related to the effort we are trying to treat |
|
Apologies for not following all the nuances, but does this imply |
It should be safe, but I think it may make sense to provide it explicitly by |
I think we should document |
Sorry, now I think I see the rule behind this a bit clearer now. Let me confirm.
Is my understanding correct? |
Yes, I think that's correct. |
Thanks, then I agree with documenting |
Uh oh!
There was an error while loading. Please reload this page.
Showing proportions (instead of counts or density) of a bin in a histogram is a common exercise, but this is not documented. Most stackoverflow suggestions are either conflicting or outdated.
The solution below by @clauswilke in a now-locked thread seems like the best practice. Could this trick as well as the
width
stat be documented in thegeom_histogram
manual and the ggplot website?Created on 2019-09-07 by the reprex package (v0.3.0)
Originally posted by @clauswilke in #2499 (comment)
The text was updated successfully, but these errors were encountered: