Using par(new=TRUE) will often cause more problems than it helps. A better approach would be to use the twoord.plot function from the plotrix package or to use the updateusr function from the TeachingDemos package along with the lines function to add the lines afterwards.
On Wed, Aug 22, 2012 at 7:43 AM, vikrant <vikrant.shi...@tcs.com> wrote: > 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. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.