Skip to content

Instantly share code, notes, and snippets.

@lyo
Last active July 28, 2019 08:37
Show Gist options
  • Save lyo/8a60f1c1feb651be45b42d655ada7737 to your computer and use it in GitHub Desktop.
Save lyo/8a60f1c1feb651be45b42d655ada7737 to your computer and use it in GitHub Desktop.
# to see
# https://www.pediatricsurgery.site/entry/2018/03/04/133703
# https://mrunadon.github.io/ggplot2/
# https://sugioka.wiki.fc2.com/wiki/ggplot2でviolinplotを描く
ggplot()+theme_set(theme_bw(base_size = 14))
mean_fun <- function(x){
return(data.frame(y = min(x)+0.5, label = paste0(round(mean(x),1))))
}
ggplot(data = iris,
mapping = aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_flat_violin(scale = "count", trim = FALSE, alpha=0.3) +
stat_summary(fun.data = mean_sdl, fun.args = list(mult = 1),
geom = "pointrange", position = position_nudge(0.05) ) +
stat_summary(fun.y = mean, geom="line", aes(group=1))+
stat_summary(fun.data = mean_fun, geom = "text",size=4)+
geom_dotplot(binaxis = "y", dotsize = 0.5, stackdir = "down", binwidth = 0.1,
position = position_nudge(-0.025), alpha=0.7) +
theme(legend.position = "none") +
ylim(3,9) +
labs(x = "Species", y = "Sepal length (cm)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment