[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)
library(vioplot)
## set up frame, without axes
plot(1,1,xlim=c(0,3.5),ylim=range(c(a,b,c)),type="n",
xlab="",ylab="",axes=FALSE)
## bottom axis, with user-specified labels
axis(side=1,at=1:3,labels=c("first","second","third"))
axis(side=2)
vioplot(a,at=1,col="blue",add=TRUE)
vioplot(b,at=2,col="red",add=TRUE)
vioplot(c,at=3,col="magenta",add=TRUE)
More information about the R-help
mailing list