Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created September 9, 2020 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateucher/41c46e8fe4923b6c8167511a8882145f to your computer and use it in GitHub Desktop.
Save ateucher/41c46e8fe4923b6c8167511a8882145f to your computer and use it in GitHub Desktop.
library(ggplot2)

iris$is_pretty <- sample(c(TRUE, FALSE), nrow(iris), replace = TRUE)

# dodge < width
ggplot(iris, aes(y = is_pretty, x = Petal.Length, fill = Species)) + 
  geom_bar(stat = "identity", position = position_dodge(0.5), width = 0.85)

# dodge = width
ggplot(iris, aes(y = is_pretty, x = Petal.Length, fill = Species)) + 
  geom_bar(stat = "identity", position = position_dodge(0.5), width = 0.5)

# dodge > width
ggplot(iris, aes(y = is_pretty, x = Petal.Length, fill = Species)) + 
  geom_bar(stat = "identity", position = position_dodge(0.85), width = 0.5)

Created on 2020-09-09 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment