Skip to content

Instantly share code, notes, and snippets.

@humanfactors
Created February 11, 2021 07:46
Show Gist options
  • Save humanfactors/9a054984a4147a6c192dc0da28b675c1 to your computer and use it in GitHub Desktop.
Save humanfactors/9a054984a4147a6c192dc0da28b675c1 to your computer and use it in GitHub Desktop.
ggplot2 frequency plot label woes
library(ggplot2)
mydata = structure(list(estimate = c(cor = 0.325795456913319, cor = 0.562197877060912,
cor = 0.440719760612754, cor = -0.0936850084700603, cor = 0.0360156238340214,
cor = 0.290449045144756, cor = 0.351442182968952, cor = 0.282652330413659,
cor = 0.484382008605981, cor = 0.555190439953125, cor = 0.153963602626727,
cor = 0.389799442186418, cor = 0.102658050525012, cor = 0.539213427685732,
cor = 0.599952880067505, cor = 0.353135730646411, cor = 0.5459587711875,
cor = 0.380085983041004, cor = 0.494013540678857, cor = 0.506029397264374,
cor = 0.796184962852028, cor = 0.152349436981737, cor = 0.474356676277947,
cor = 0.585975728042781, cor = 0.278773851537417, cor = 0.380637414940095,
cor = 0.392275909026939, cor = 0.419554193309306, cor = 0.488358015824324,
cor = 0.199407247922171, cor = 0.260254145583898, cor = 0.349291291301302,
cor = 0.464177992152635, cor = 0.0747318120424813, cor = 0.60432048579698,
cor = 0.295662258461811, cor = 0.0278690641141737, cor = -0.0337558821556421,
cor = 0.211670641689536, cor = 0.285200869849266, cor = 0.51828476555577,
cor = 0.44882613302634), groupid = 1:42,
magnitiude = structure(c(4L, 5L, 4L, 1L, 2L, 3L, 4L, 3L, 4L, 5L, 3L, 4L, 3L, 5L, 5L, 4L, 5L,
4L, 4L, 5L, 5L, 3L, 4L, 5L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L,
2L, 5L, 3L, 2L, 1L, 3L, 3L, 5L, 4L),
.Label = c("Negative", "Negligible", "Small", "Medium", "Large"), class = "factor")),
row.names = c(NA, -42L), class = c("tbl_df", "tbl", "data.frame"))
ggplot(data = mydata, aes(estimate)) +
stat_bin(aes(fill = magnitiude, group = groupid, label=estimate), color = "#424242", binwidth = 0.05) +
stat_bin(binwidth=0.05, geom="text", aes(label=round(estimate,2), group = groupid), position=position_stack(vjust=0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment