holgerbrandl / kravis

A {K}otlin g{ra}mmar for data {vis}ualization
BSD 2-Clause "Simplified" License
183 stars 12 forks source link

support for half violin plots with dot overlay #9

Closed holgerbrandl closed 6 years ago

holgerbrandl commented 6 years ago
# half violin plot with raw data ------------------------------------------

## create a violin plot of Sepal.Length per species
## using the custom function geom_flat_violin()

ggplot(data = iris, 
       mapping = aes(x = Species, y = Sepal.Length, fill = Species)) + 
  geom_flat_violin(scale = "count", trim = FALSE) + 
  stat_summary(fun.data = mean_sdl, fun.args = list(mult = 1), 
               geom = "pointrange", position = position_nudge(0.05)) + 
  geom_dotplot(binaxis = "y", dotsize = 0.5, stackdir = "down", binwidth = 0.1, 
               position = position_nudge(-0.025)) + 
  theme(legend.position = "none") + 
  labs(x = "Species", y = "Sepal length (cm)")

See https://helenajambor.wordpress.com/2018/08/28/pick-n-mix-plots/