library(ggplot2)
set.seed(1234)
x = rnorm(200, 1, 2)
# If we manually specify a bin width using breaks_fixed(), the default
# alignment (align_none()) will not align bin edges to any "pretty" numbers.
# Here is a comparison of the three alignment methods on such a histogram:
ggplot(data.frame(x), aes(x)) +
stat_slab(
aes(y = "none"),
density = "histogram",
breaks = breaks_fixed(width = 1),
outline_bars = TRUE,
# no need to specify align; align_none() is the default
color = "black",
) +
stat_slab(
aes(y = "center at 0"),
density = "histogram",
breaks = breaks_fixed(width = 1),
align = align_center(at = 0), # or align = "center"
outline_bars = TRUE,
color = "black",
) +
stat_slab(
aes(y = "boundary at 0"),
density = "histogram",
breaks = breaks_fixed(width = 1),
align = align_boundary(at = 0), # or align = "boundary"
outline_bars = TRUE,
color = "black",
) +
geom_point(aes(y = 0.7), alpha = 0.5)
Run the code above in your browser using DataLab