Several colors on beanplot in R

I created a bean plot in R using the following

beanplot(windA, side='both', border='NA', 
        col=list('gray',c('red','white')),
        ylab='Wind Speed (m/s)' ,what=c(1,1,1,0),xaxt ='n')

axis(1,at=c(1:12),labels =c  ('Jan','Feb','Mar','apr','may','Jun','Jul','Aug','Sep','Oct','Nov','Dec'))
legend('topright', fill=c('gray','red'), legend= c('Measured', 'calc'))

and I get the following image enter image description here

Is there a way I can alternate colors? For example, can I have Jan be gray and red and then Feb be gray and blue and continue this alternating color scheme throughout the year?

+2
source share
1 answer

you can specify the desired color, col=list('gray','red','grey','blue')using a sample of data USArrestsfrom the database R, the colors will be cyclically repeated until all points are plotted

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

enter image description here

+4
source

All Articles