[R] ploting the two sets of data side by side

P Ehlers ehlers at math.ucalgary.ca
Wed Dec 7 15:43:03 CET 2005


As usual, Gabor provides an elegant solution. But I hope that, in
this case, the OP provided a toy example. Otherwise, I don't see
the point of applying cut() to a vector of length 7. Why not just
use stripchart()?

Peter Ehlers

Gabor Grothendieck wrote:

> Or building on that solution but eliminating the do.call and lapply:
> 
> f <- function(x) table(cut(x, breaks = seq(0, 30, 5)))
> barplot(rbind(f(x), f(y)), beside = TRUE)
> 
> On 12/7/05, Jacques VESLOT <jacques.veslot at cirad.fr> wrote:
> 
>>try :
>>
>>barplot(do.call("rbind",lapply(list(x,y), function(x) table(cut(x,
>>breaks =c(0,5,10,20,25,30))))),beside=T)
>>
>>Subhabrata a écrit :
>>
>>
>>>Hello R-users,
>>>
>>>I am new to R-commands.
>>>
>>>
>>>I have two sets of data:
>>>
>>>x <- c(7, 7 , 8, 9, 15, 17, 18)
>>>y <- c(7, 8, 9, 15, 17, 19, 20, 20, 25, 23, 22)
>>>
>>>
>>>I have used 'cut' command to seperate them as follows
>>>
>>>a <- cut(x, breaks =c(0,5,10,20,25,30))
>>>
>>>b <- cut(y, breaks =c(0,5,10,20,25,30))
>>>
>>>
>>>
>>>
>>>>table(a)
>>>>
>>>>
>>>
>>>a
>>> (0,5]  (5,10] (10,20] (20,25] (25,30]
>>>     0       4       3       0       0
>>>
>>>
>>>
>>>>table(b)
>>>>
>>>>
>>>
>>>b
>>> (0,5]  (5,10] (10,20] (20,25] (25,30]
>>>     0       3       5       3       0
>>>
>>>
>>>Now if I want to a single graph with both sets of data side by side for same range.
>>>
>>>Can some one help me regarding the above problem.
>>>
>>>With Regards
>>>Subhabrata Pal
>>>subhabratapal at sraindia.com
>>>      [[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
>>>
>>>
>>>
>>
>>______________________________________________
>>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
>>
> 
> 
> ______________________________________________
> 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




More information about the R-help mailing list