[R] About colours in violin and simple violin plots

Ben Bolker bolker at ufl.edu
Thu Aug 7 03:05:18 CEST 2008

Fernando Marmolejo Ramos <fernando.marmolejoramos <at> adelaide.edu.au> writes:

> Dear R users
> Let’s assume I have the following batches of data
> a <- rnorm(20,200,100)
> b <- rnorm(20,250,100)
> c <- rnorm(20,300,100)
> # I plot them as violin plots
> require(vioplot)
> vioplot(a, b, c)
> # I plot them as simple violin plots
> require(UsingR)
> simple.violinplot(a, b, c)
> # I plot them as boxplots
> boxplot(a, b, c)
> # I know that for boxplots I can colour them by col=c("white", "blue", "red")
> # but this does not work for the other plots 
> The question is:
> How can I give different colours to each violin plot?
> How can I put labels to each violin/boxplot plot instead of the numbers that
> appear underneath them?

  Short of hacking vioplot (which would be reasonable, the
code isn't too complicated), the easiest thing is to set up
your own frame for the plot and then use add=TRUE to add the
violinplots one at a time ...

a <- rnorm(20,200,100)
b <- rnorm(20,250,100)
c <- rnorm(20,300,100)


## set up frame, without axes
## bottom axis, with user-specified labels

More information about the R-help mailing list