[R] Barplot with Secondary axis
vikrant
vikrant.shimpi at tcs.com
Wed Aug 22 15:43:28 CEST 2012
Hi all,
I am trying to plot a bar chart and trying to plot a line as a secondary
axis as my scale is different for two y axis.
I am plotting a clustered bar chart by using besides = True option in
barplot function and my y coordinates are not plotted exactly at the center
on each two bars. Please help me.
I am pasting the code as follows.
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)
barplot(t(y),beside = TRUE)
par(new=T)
plot(y2,,,type="o",col="black",lwd=
3,lty=1,xaxt="n",yaxt="n",xlab="",ylab="")
points(y2,pch=20)
I also tried following code for plotting the line point exactly at the
center of two bars:
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)
barplot(t(y),beside = TRUE)
a = barplot(t(y),beside = TRUE)
par(new=T)
plot(colMeans(a),y2,type="l",col="black",lwd=
1,lty=1,xaxt="n",yaxt="n",xlab="",ylab="")
points(colMeans(a),y2,pch=20)
Please help me in plotting this graph
--
View this message in context: http://r.789695.n4.nabble.com/Barplot-with-Secondary-axis-tp4640980.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list