I have searched for an answer to this but am drawing a blank. I'm trying to weight occurrences in ggplot violin, but get a warning that
In density.default(x, weights = w, bw = bw, adjust = adjust, kernel = kernel, :
sum(weights) != 1 -- will not get true density
I have reproduced the error below using mtcars dataset (my x is a factor, y is continuous and weight is numeric as reproduced below). In my own data set I need to apply a weighting to control for the time data was collected.
mtcars$cyl <- as.factor(mtcars$cyl) myplot3 <- ggplot(mtcars, mapping=aes(x=cyl, y=drat, weights = qsec/sum(qsec)))+ geom_violin(scale = "count") + labs(title="My plot", x="Name", y="Position") myplot3
Can anyone advise on how to apply weighting correctly? I also want to be able to see the scale="count" as my own data has skewed abundances between factors, which I need to view graphically.
Thanks in advance.