Hello, I have a very simple question about "2 barplots in the same graph". It seems quite easy, but I searched google for long time, haven't find solution. For example, I want one graph like: x1=seq(0,2,by=0.3) x2=seq(3,0,by=-0.1) barplot(x1,col="red") barplot(x2,col="green") It means if it's on the same graph, some bars are overlaped. So if the bars are hollow, instead of filled with color, it will be better. Actually, I think it's something similar with matlab's "hold on" command. Thanks! Nina [[alternative HTML version deleted]]
See ?barplot If I understand what you want, try: barplot(x1,border="red",density=0) par(new=TRUE) barplot(x2,border="green",density=0) Rob ____________________________ Robert W. Baer, Ph.D. Associate Professor Department of Physiology A. T. Still University of Health Science 800 W. Jefferson St. Kirksville, MO 63501-1497 USA ----- Original Message ----- From: "jia ding" <dingjia at gmail.com> To: "R-help" <r-help at stat.math.ethz.ch> Sent: Wednesday, February 22, 2006 7:31 AM Subject: [R] 2 barplots in the same graph> Hello, > > I have a very simple question about "2 barplots in the same graph". > > It seems quite easy, but I searched google for long time, haven't find > solution. > > For example, I want one graph like: > x1=seq(0,2,by=0.3) > x2=seq(3,0,by=-0.1) > barplot(x1,col="red") > barplot(x2,col="green") > > It means if it's on the same graph, some bars are overlaped. > So if the bars are hollow, instead of filled with color, it will bebetter.> > Actually, I think it's something similar with matlab's "hold on" command. > > Thanks! > > Nina > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html>
On Wed, 2006-02-22 at 14:31 +0100, jia ding wrote:> Hello, > > I have a very simple question about "2 barplots in the same graph". > > It seems quite easy, but I searched google for long time, haven't find > solution. > > For example, I want one graph like: > x1=seq(0,2,by=0.3) > x2=seq(3,0,by=-0.1) > barplot(x1,col="red") > barplot(x2,col="green") > > It means if it's on the same graph, some bars are overlaped. > So if the bars are hollow, instead of filled with color, it will be better. > > Actually, I think it's something similar with matlab's "hold on" command. > > Thanks! > > NinaI may be misinterpreting your question, but do you want something like this? x1 <- seq(0, 2, by = 0.3) x2 <- seq(3, 0, by = -0.1) # Set bar fill to white, border to green barplot(x2, col = "white", border ="green") # Set bar fill to white, border to red and add to prior plot barplot(x1, col = "white", border = "red", add = TRUE) See the 'add' and 'border' arguments in ?barplot. HTH, Marc Schwartz
The barplot solution already presented is probably what you want but just in case here is a zoo solution: library(zoo) z <- merge(zoo(x2), zoo(x1, seq(x1)+.5)) plot(z, type = "h", plot.type = "single", col = 1:2, lwd = 5) Or a similar solution without zoo: plot(c(x1, x2) ~ c(seq(x1)+.5, seq(x2)), col = c(1+0*x1, 2+0*x2), type = "h", lwd = 5) On 2/22/06, jia ding <dingjia at gmail.com> wrote:> Hello, > > I have a very simple question about "2 barplots in the same graph". > > It seems quite easy, but I searched google for long time, haven't find > solution. > > For example, I want one graph like: > x1=seq(0,2,by=0.3) > x2=seq(3,0,by=-0.1) > barplot(x1,col="red") > barplot(x2,col="green") > > It means if it's on the same graph, some bars are overlaped. > So if the bars are hollow, instead of filled with color, it will be better. > > Actually, I think it's something similar with matlab's "hold on" command. > > Thanks! > > Nina > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >