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("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/10_OneNumSevCatSubgroupsSevObs.csv", 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!
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("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/10_OneNumSevCatSubgroupsSevObs.csv", 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))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With