[R] 2 barplots in the same graph

Romain Francois francoisromain at free.fr
Fri Feb 24 11:31:26 CET 2006


Le 24.02.2006 11:17, jia ding a écrit :
> Thanks All!
>
> I combine your answers and post the code here again, if later somebody need
> it.
>
> Actually, what I want is:
>   
>> x1
>>     
> [1]  1  2 10
>   
>> x2
>>     
> [1] -3  5 -8
>   
>> barplot(x1,col="white",border="red")
>> barplot(x2,col="white",border="green",add=T)
>>     
> So that, the two plots even share the same x-axis.
>
> But, It comes another question: >
> barplot(x2,col="white",border="green",add=T), because there are 2 numbers
> are negative, some part of the bar is missing. Is there any automatic
> function to make the axes fit very well for both bars?
>
>   
R> barplot(x1,col="white",border="red", ylim=range(c(x1,x2)))
> And, suppose I want to add another command: axis(1, 0:20) to draw x-axis. I
> notice it  increase like: 0,1,2,3,...20; how can I make it 0,5,15,20?
>
>   
before doing axis(1, 0:20) have you tried to do
R> 0:20

So,

R> axis(1, (0:4)*5)
or
R> axis(1, c(0,5, 10, 15, 20))
or
R> axis(1, seq(0,20, by=5))

it's up to you. There are probably other solutions as well
> Thanks!
>
>   
You're welcome

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