Adding Mean to Grouped Violin Plot
Good Evening, I Have a Dataset Like the Following and I'm Trying to Compute Grouped Violinplots. That All Works. but Now I'd Like to Add Mean Values + Standard...
Good evening, I have a dataset like the following and I'm trying to compute grouped violinplots. That all works. But now I'd like to add mean values + Standard deviations and if I add the order for that it looks very weird, so I guess the approach is different for grouped violin plots.
library(tidyverse)
# Load dataset from github
data <- read.table("", header=T, sep=",") %>%
mutate(tip = round(tip/total_bill*100, 1))
# Grouped
data %>%
ggplot(aes(fill=sex, y=tip, x=day)) +
geom_violin(trim = FALSE, position="dodge", alpha=0.5) +
xlab("") +
ylab("Tip (%)") +
ylim(0,40) +
stat_summary(fun.data=mean_sdl, fun.args = list(mult = 1),
geom="pointrange", color="black", shape = 18, size = 0.75)
I would be very glad if somebody could help me out :)
thank you!
1 Answer
If you specify "position" and "width" you should be able to get them into the correct alignment, e.g.
library(tidyverse)
# Load dataset from github
data <- read.table("", header=T, sep=",") %>%
mutate(tip = round(tip/total_bill*100, 1))
# Grouped
data %>%
ggplot(aes(fill=sex, y=tip, x=day)) +
geom_violin(trim = FALSE, position="dodge", alpha=0.5) +
xlab("") +
ylab("Tip (%)") +
ylim(0,40) +
stat_summary(fun.data=mean_sdl, fun.args = list(mult = 1),
geom="pointrange", color="black",
shape = 18, size = 0.75,
position = position_dodge(width = 0.9))