Skip to content
Prev 303917 / 398513 Next

Barplot with Secondary axis

Hello,
You were almost there.


x = c("a","b","c","d")
y= cbind(c(50,40,30,20),c(40,30,20,10))
y2 = c(0.80,0.65,0.75,0.50)
#
bp <- barplot(t(y), beside = TRUE)
xlim <- c(floor(min(bp)), ceiling(max(bp)))
#
par(new=T)
plot(colMeans(bp), y2, type="o", col="black", lwd=3,
     lty=1, xaxt="n", yaxt="n", xlab="", ylab="", xlim = xlim)
points(colMeans(bp), y2, pch=20)


The trick was to get rid of xaxt = "n" for a while, to see what was 
going on with the x axis: it wasn't only the y axis that was changing. 
An act accordingly.

Hope this helps,

Rui Barradas

Em 22-08-2012 14:43, vikrant escreveu: