vioplot
vioplot copied to clipboard
Add horizontal line?
Is there a way to add a horizontal line to your violin plots?
Thank you for this package! I tried making my figure in ggplot and man, was it ugly. Your function looks much better.
@GCAT01 can you clarify what type of horizontal line you are referring to? For example, does the following satisfy your need?
data <- iris[, 1:3]
vioplot::vioplot(data)
abline(h = mean(data[, 1]), col = "red")
I was hoping to add a horizontal line at a specific value as if I was using abline.
I don't believe there is a way to do this with vioplot, but you can always do it manually. For example:
data <- iris[, 1:3]
vioplot::vioplot(data)
# for every column of the data
for(i in seq_len(ncol(data))){
# draw a line at the mean of each column with the width of
# 0.5 symmetrically on both sides of the violin
lines(x = c(i-0.25, i+0.25),
y = rep.int(mean(data[, i]), 2),
col = "red")
}