set.seed(123)
x <- c(rnorm(100), rnorm(100, mean = 2))
group <- rep(c("A", "B"), each = 100)
wts <- c(rep(1, 100), runif(100, 0.5, 2))
wtd.violinplot(x, group = group, weight = wts,
col = c("lightblue", "lightgreen"))
x2 <- c(seq(0,2,length.out=100), seq(0,6,length.out=100))
wts2 <- rep(1, 200)
wtd.violinplot(x2, group = group, weight = wts2,
col = c("lightblue", "lightgreen"))
wtd.violinplot(x2, group = group, weight = (wts2+.1)/(x2+.1),
col = c("lightblue", "lightgreen"))
Run the code above in your browser using DataLab