Re: [R] 2 barplots in the same graph

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Thu 23 Feb 2006 - 02:57:01 EST

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!
>
> Nina

I 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



R-help@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 Received on Thu Feb 23 03:45:31 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 06:23:11 EST