Re: [R] 2 barplots in the same graph

From: Romain Francois <francoisromain_at_free.fr>
Date: Fri 24 Feb 2006 - 22:58:53 EST

Le 24.02.2006 11:58, jia ding a écrit :
> Hi,
> Would you pls try these?
>
> x1<-c(1,2,10)
> x2<-c(-3,5,-8)
> barplot(x1,col="white",border="red",ylim=range(c(x1,x2)))
> barplot(x2,col="white",border="green",ylim=range(c(x1,x2)),add=T)
> axis(1, 0:3)
> box()
>
ylim is not needed on the second call.

>
> Q1, on x-axis "1,2,3" is not shown at the middle position of the bars.
> e.g for first bar, "1" is tend to right ; while third bar, "3" is tend
> to left.

Use the outputs from barplot :

out <- barplot(x1,col="white",border="red",ylim=extendrange(c(x1,x2))) out
axis(1, out[,1], sprintf('bar %d', 1:3))

> Q2, once >box(), then bars are cut again.

You can use extendrange instead of range, ie :

barplot(x1,col="white",border="red",ylim=extendrange(c(x1,x2)))

> Q3, when y-axis is "0", I want to draw a parallel line to x-axis:
> I tried >lines(c(0,5),c(0,0)) ; is there any other way to do it?

abline(h=0)

> Thanks.
>
> Nina

Also, try :
?barplot
http://addictedtor.free.fr/graphiques/search.php?q=barplot

Romain

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
Discover the R Movies Gallery : http://addictedtor.free.fr/movies
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+

______________________________________________
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 Fri Feb 24 23:12:44 2006

This archive was generated by hypermail 2.1.8 : Sat 25 Feb 2006 - 00:08:47 EST