It's unfortunate that vioplot doesn't accept vectors for some of its parameters. Here's a workaround. The helpful features in vioplot()
for this workaround are the at
and wex
parameters along with add=T
. Basically plot each violin individually with the parameters that shape them the way you want. You may need to make adjustments to the way you scale the sample size for use with wex
.
n<-c(100,1000)
size<-scale(sqrt(n),center=F)
x1<-rnorm(n[1])
x2<-rnorm(n[2])
#initialize an empty plot
plot(0:3,rep(0,4),type='l',xlim=c(0,3),ylim=c(-4,4),ylab="",xlab="",xaxt="n",lty=3)
# fill in the violins at specific x locations using the `wex` parameter for size
vioplot(x1,at=1,wex=size[1],add=T,col="darkgray")
vioplot(x2,at=2,wex=size[2],add=T,col="darkgray")
axis(1,at=1:2,labels=c("Mon","Tues"))