[R] A line for SD, colouring simplevioplots, limiting Y axis in barplots, axis in vioplot

Fernando Marmolejo Ramos fernando.marmolejoramos at adelaide.edu.au
Fri Oct 24 01:55:57 CEST 2008

Dear R people

I have 4 questions about graphics.

-------- QUESTION 1 & 2 -------

I have the following data, which is also set as a dataframe. Then I plot it
using a violin plot

1. How can a draw a line representing 2 SD for each group?
2. How can I colour the simple violin plots in different colours (e.g., Group A
white, Group B grey)?


a = rnorm(25, 100, 50)
b = rnorm(25, 300, 50)

# --- dataframing the vectors...
adf <- data.frame(Group = " Group A ", Measure = a)
bdf <- data.frame(Group = " Group B ", Measure = b)

## Combine into a dataframe using rbind
abtruncdata <- rbind(adf, bdf)

with(abtruncdata, simple.violinplot(Measure~Group))

with(abtruncdata, plotmeans(Measure ~ Group, pch=16, mean.labels=TRUE, col=
c("blue", "red"), digits=2, add=T, p=0.95, barcol=c("blue", "red"), use.t=T,
n.label=F, connect=F, ci.label=F))

-------- QUESTION 3 -------

I have the following bar plot for the same data
3. how can I set the “ylim”, lets say from 50 to 350 in steps of 25?

tmp = split(Measure, Group)

means = sapply(tmp, mean)

stdev = sapply(tmp, sd)

plotCI(barcol="blue", pch=16, col="blue", barplot(means, col=c("white",
       ylim=c(0,max(means + stdev)), xlab = "Error bars: ±1SD", ylab="Measure"),
         means, stdev, add=TRUE)

-------- QUESTION 4 -------

The same data frame now as violin plot
4. How can I keep a violinplot frame a la simple.violinplot?

## set up frame, without axes

     xlab="  ",ylab="Median measure",axes=FALSE)

## bottom axis, with user-specified labels
axis(side=1,at=1:2,labels=c("Group A","Group B"))

# but as soon as I call the first violinplot, the upper and right axes appear

In advance, thank you for your answers!



More information about the R-help mailing list