r - how can I create violin plot in different colours? -
i using bundle vioplot. ask, how can create violinplot in different colours.
this reproducible example:
# violin plots library(vioplot) x1 <- mtcars$mpg[mtcars$cyl==4] x2 <- mtcars$mpg[mtcars$cyl==6] x3 <- mtcars$mpg[mtcars$cyl==8] vioplot(x1, x2, x3, names=c("4 cyl", "6 cyl", "8 cyl"), col="gold") title("violin plots of miles per gallon") thank you.
it not possible have many colors. not hard hack function vioplot , edit source code. here steps should follow accomplish this:
copy initial function:
my.vioplot <- vioplot() edit function:
edit(my.vioplot) search word "polygon" , and replace col col[i]
do test in origin of function case give single color. , add together line :
if(length(col)==1) col <- rep(col,n) for illustration using info :
vioplot(x1, x2, x3, names=c("4 cyl", "6 cyl", "8 cyl"), col="gold") title("violin plots of miles per gallon") my.vioplot(x1, x2, x3, names=c("4 cyl", "6 cyl", "8 cyl"), col=c("gold","red","blue")) title("violin plots of miles per gallon multi colors") r
No comments:
Post a Comment