[R] Barplot - Can't figure it out
BXC (Bendix Carstensen)
bxc at steno.dk
Fri Feb 18 13:48:00 CET 2005
What you want is probably:
> cxy <- c(x,y)
> xy <- rep( c("x","y"), c(length(x),length(y)) )
> ( txy <- table(xy, cxy ) )
cxy
xy 2 3 4 5
x 0 6 4 0
y 4 0 1 5
> barplot( txy, beside=T )
Bendix Carstensen
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc
----------------------
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of T Petersen
> Sent: Friday, February 18, 2005 1:01 PM
> To: Petr Pikal
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Barplot - Can't figure it out
>
>
> Wow, I'm getting confused...The syntax Petr suggested does what I
> wanted, but things are stille wrong...Maybe a bug? Let me explain.
>
> I got two vectors:
>
> x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4)
>
> y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2)
>
> then I do the barplot you suggest
>
> barplot(rbind(table(x), table(y)), beside=T)
>
> but things are wrong(there is no bar for catagory "3") and I
> get an error message: Warning message:
> number of columns of result
> not a multiple of vector length (arg 1) in:
> rbind(table(Quest1), table(Quest2))
>
> Any ideas?
More information about the R-help
mailing list