[R] 2 barplots in the same graph
Romain Francois
francoisromain at free.fr
Fri Feb 24 12:58:53 CET 2006
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 |
+---------------------------------------------------------------+
More information about the R-help
mailing list