My data looks like this below:
> head(links_dat)
set_num alllinks
1 None 8
2 None 3
3 None 9
4 None 3
5 None 2
6 None 2
There are four categories of set_num
, alllinks
is numeric. I want to plot the violin plot of the alllins
across set_num
, and also add the average value for corresponding distributions. I find the average of the third category is higher than the forth, but it shows a lower position in the plot. Can someone explain this for me?
Here is my plot code:
p <- ggplot(links_dat, aes(x = set_num, y = alllinks, fill = set_num)) +
geom_violin(trim = FALSE) +
stat_summary(fun.y = mean, geom = "point", size = 0.5, color = "red") +
scale_y_log10(labels = label_number()) +
scale_fill_brewer(palette = "Blues") +
theme_classic()