Color of individual lines in beanplot

I would like to change the colors of individual lines in a beanplot. Using col, I can change the color of the bean area, all lines inside the bean, all lines outside the bean, and the middle line to bean. I would like to assign different colors to different lines depending on the variable.

x <- rnorm(15)
beanplot(x,ll = 1, col = c(0,1,1,2),
                 side = "both", axes = FALSE,method = "stack")

I would like to assign colors based on colpref vector

colpref <- c(5, 5, 3, 5, 5, 3, 5, 5, 3, 3, 5, 5, 5, 3, 3)
+4
source share
1 answer

you can play with options addand whatlike this

beanplot(x[colpref==3],ll = 1, col = c(0,3,3,3), what=c(1,0,1,1),
         side = "both", axes = FALSE,method = "stack", add=FALSE)
beanplot(x[colpref==5],ll = 1, col = c(0,5,5,5), what=c(1,0,1,1),
         side = "both", axes = FALSE,method = "stack", add=TRUE)
beanplot(x,ll = 1, col = c(0,5,5,5), what=c(0,1,0,0),
         side = "both", axes = FALSE,method = "stack", add=TRUE)

enter image description here

+4
source

All Articles