Markm0705 Markm0705 - 25 days ago 9
R Question

R beanplot change the colour and length of the average line

Consider the following beanplot image in R ...

require(beanplot)
beanplot(USJudgeRatings,
side='both',
border='NA',
col=list('gray','red'),
ylab='US Judge Ratings',
what=c(1,1,1,1))


The beanplot helps is says "col ... A vector of up to four colors can be used. In the following order, these colors stand for the area of the beans (without the border, use border for that color), the lines inside the bean, the lines outside the bean, and the average line per bean."

However, I don't understand from the help how to specify the colour of the rug lines and average lines on each bean - guidance would be appreciated (and why does the colour vector have to be defined as a list give the different colours on each side of the paired halves) Is it possible to change the length of the average line?

Answer Source

You need to define col as a list of vectors with 4 colours. Here is an example.

require(beanplot)
beanplot(USJudgeRatings, 
     side='both', 
     border='NA', 
     col=list(c('gray','black',"black","green"),c('red','white',"black","blue"),
              c('#ffffb2','black',"black","#f03b20"),c('#fd8d3c','white',"black","#bd0026")) ,
     ylab='US Judge Ratings',
     what=c(1,1,1,1))

enter image description here