Re: [R] Barplot - Can't figure it out

2005-02-18 Thread Petr Pikal
Hi

If I understand correctly

barplot(rbind(table(x), table(y)), beside=T)

does what you want.

Cheers
Petr



On 18 Feb 2005 at 7:51, T Petersen wrote:

 Almost. Catagories aren't stacked - I would like to see that x has 2
 instances of 1 while y has 1 instance of 1. What's more, there are
 now TWO distinct barplots - the left one shows x, while the right one
 shows y. I could live with that, but what I'd ideally want is to have
 x and y beside each other for EACH catagory - so for catagory 1 you
 could see taht there are more x's than y's (two x's versus one y). But
 thanks for the help
 
 Mulholland, Tom wrote:
 
 barplot(matrix(c(x,y),ncol = 2),beside=T)
 
 Does this help 
  
 ?barplot notes
 
 height: either a vector or matrix of values describing the bars which
   make up the plot.  If 'height' is a vector, the plot
   consists of a sequence of rectangular bars with heights
   given by the values in the vector.  If 'height' is a matrix
   and 'beside' is 'FALSE' then each bar of the plot
   corresponds to a column of 'height', with the values in the
   column giving the heights of stacked sub-bars making up
   the bar.  If 'height' is a matrix and 'beside' is 'TRUE',
   then the values in each column are juxtaposed rather than
   stacked.
 
 
   
 
 -Original Message-
 From: T Petersen [mailto:[EMAIL PROTECTED]
 Sent: Friday, 18 February 2005 1:35 PM
 To: Kevin Wang
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Barplot - Can't figure it out
 
 
 Ups, it should of course be barplot() in my mail, not boxplot:-)
 
 Kevin Wang wrote:
 
 
 
 Hi,
 
 T Petersen wrote:
 
   
 
 Hi,
 
 I have two catagorical vectors like this;
 
 x = c(1, 2, 4, 2, 1)
 y = c(2, 4, 2 ,4, 1)
 
 I want to set up a barplot with the catagories 1-4 
 
 
 horizontally  and 
 
 
 number of occurances vertically for each vector x,y. I've tried
 
 boxplot(table(x,y), beside=T)
 
 and
 
 boxplot(c(x,y), beside=T)
 
 
 Have you tried barplot(), instead of boxplot()???
 
 Cheers,
 
 Kev
 
   
 
 __
 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
 
 
 
 
 __
 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
 
   
 
 
 __
 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

Petr Pikal
[EMAIL PROTECTED]

__
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


Re: [R] Barplot - Can't figure it out

2005-02-18 Thread T Petersen
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?
Petr Pikal wrote:
Hi
If I understand correctly
barplot(rbind(table(x), table(y)), beside=T)
does what you want.
Cheers
Petr

On 18 Feb 2005 at 7:51, T Petersen wrote:
 

Almost. Catagories aren't stacked - I would like to see that x has 2
instances of 1 while y has 1 instance of 1. What's more, there are
now TWO distinct barplots - the left one shows x, while the right one
shows y. I could live with that, but what I'd ideally want is to have
x and y beside each other for EACH catagory - so for catagory 1 you
could see taht there are more x's than y's (two x's versus one y). But
thanks for the help
Mulholland, Tom wrote:
   

barplot(matrix(c(x,y),ncol = 2),beside=T)
Does this help 

?barplot notes
height: either a vector or matrix of values describing the bars which
make up the plot.  If 'height' is a vector, the plot
consists of a sequence of rectangular bars with heights
given by the values in the vector.  If 'height' is a matrix
and 'beside' is 'FALSE' then each bar of the plot
corresponds to a column of 'height', with the values in the
column giving the heights of stacked sub-bars making up
the bar.  If 'height' is a matrix and 'beside' is 'TRUE',
then the values in each column are juxtaposed rather than
stacked.

 

-Original Message-
From: T Petersen [mailto:[EMAIL PROTECTED]
Sent: Friday, 18 February 2005 1:35 PM
To: Kevin Wang
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Barplot - Can't figure it out
Ups, it should of course be barplot() in my mail, not boxplot:-)
Kevin Wang wrote:
  

   

Hi,
T Petersen wrote:


 

Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 
  

   

horizontally  and 
  

   

number of occurances vertically for each vector x,y. I've tried
boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
  

   

Have you tried barplot(), instead of boxplot()???
Cheers,
Kev


 

__
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

  

   

__
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

 

__
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
   

Petr Pikal
[EMAIL PROTECTED]
__
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
 

__
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


Re: [R] Barplot - Can't figure it out

2005-02-18 Thread Achim Zeileis
On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote:

 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?

If x and y are categorical variables, you should tell R so (i.e.,
convert to a factor) and if both should have the same categories (i.e.,
levels) you can supply this information as well:

R x - factor(x, levels = 2:5)
R y - factor(y, levels = 2:5)

Then, table() knows which categories to use:

R rbind(x = table(x), y = table(y))
  2 3 4 5
x 0 6 4 0
y 4 0 1 5

and also the barplot() call given above will do the right thing.
Z

 Petr Pikal wrote:
 
 Hi
 
 If I understand correctly
 
 barplot(rbind(table(x), table(y)), beside=T)
 
 does what you want.
 
 Cheers
 Petr
 
 
 
 On 18 Feb 2005 at 7:51, T Petersen wrote:
 
   
 
 Almost. Catagories aren't stacked - I would like to see that x has 2
 instances of 1 while y has 1 instance of 1. What's more, there
 arenow TWO distinct barplots - the left one shows x, while the right
 oneshows y. I could live with that, but what I'd ideally want is to
 havex and y beside each other for EACH catagory - so for catagory
 1 youcould see taht there are more x's than y's (two x's versus
 one y). Butthanks for the help
 
 Mulholland, Tom wrote:
 
 
 
 barplot(matrix(c(x,y),ncol = 2),beside=T)
 
 Does this help 
 
 ?barplot notes
 
 height: either a vector or matrix of values describing the bars
 which make up the plot.  If 'height' is a vector, the plot
  consists of a sequence of rectangular bars with heights
  given by the values in the vector.  If 'height' is a
 matrix and 'beside' is 'FALSE' then each bar of the plot
  corresponds to a column of 'height', with the values in
 the column giving the heights of stacked sub-bars making
 up the bar.  If 'height' is a matrix and 'beside' is
 'TRUE', then the values in each column are juxtaposed
 rather than stacked.
 
 
  
 
   
 
 -Original Message-
 From: T Petersen [mailto:[EMAIL PROTECTED]
 Sent: Friday, 18 February 2005 1:35 PM
 To: Kevin Wang
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Barplot - Can't figure it out
 
 
 Ups, it should of course be barplot() in my mail, not boxplot:-)
 
 Kevin Wang wrote:
 

 
 
 
 Hi,
 
 T Petersen wrote:
 
  
 
   
 
 Hi,
 
 I have two catagorical vectors like this;
 
 x = c(1, 2, 4, 2, 1)
 y = c(2, 4, 2 ,4, 1)
 
 I want to set up a barplot with the catagories 1-4 

 
 
 
 horizontally  and 

 
 
 
 number of occurances vertically for each vector x,y. I've tried
 
 boxplot(table(x,y), beside=T)
 
 and
 
 boxplot(c(x,y), beside=T)

 
 
 
 Have you tried barplot(), instead of boxplot()???
 
 Cheers,
 
 Kev
 
  
 
   
 
 __
 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
 

 
 
 
 __
 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
 
  
 
   
 
 __
 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
 
 
 
 Petr Pikal
 [EMAIL PROTECTED]
 
 __
 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
 
   
 
 
 __
 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


__
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


RE: [R] Barplot - Can't figure it out

2005-02-18 Thread BXC (Bendix Carstensen)
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
[EMAIL PROTECTED]
www.biostat.ku.dk/~bxc
--



 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of T Petersen
 Sent: Friday, February 18, 2005 1:01 PM
 To: Petr Pikal
 Cc: r-help@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?

__
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


Re: [R] Barplot - Can't figure it out

2005-02-18 Thread Petr Pikal


On 18 Feb 2005 at 13:00, T Petersen wrote:

 Wow, I'm getting confused...The syntax Petr suggested does what I
 wanted, but things are stille wrong...Maybe a bug? Let me explain.

Bugs are exceptionally rare in R.

 
 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)
 

So you do not have same categories in both vectors.

The only thing I can come up with is to fill some dummy vector, like

xx-rep(NA,5)

with

xx[1:5 %in% as.numeric(names(table(x)))]-table(x)

to keep both vectors same length and with NA in place where there is 
no category. Than simply rbinding both vectors and making barplot.


 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))

warning message says exactly what it says

table(Quest1) and table(Quest2) does not result in the same 
categories, so rbinding vectors with different lengths is performed, 
shorter vector is recycled and warning is issued.


Cheers
Petr



 
 Any ideas?
 
 Petr Pikal wrote:
 
 Hi
 
 If I understand correctly
 
 barplot(rbind(table(x), table(y)), beside=T)
 
 does what you want.
 
 Cheers
 Petr
 
 
 
 On 18 Feb 2005 at 7:51, T Petersen wrote:
 
   
 
 Almost. Catagories aren't stacked - I would like to see that x has 2
 instances of 1 while y has 1 instance of 1. What's more, there
 are now TWO distinct barplots - the left one shows x, while the
 right one shows y. I could live with that, but what I'd ideally want
 is to have x and y beside each other for EACH catagory - so for
 catagory 1 you could see taht there are more x's than y's (two x's
 versus one y). But thanks for the help
 
 Mulholland, Tom wrote:
 
 
 
 barplot(matrix(c(x,y),ncol = 2),beside=T)
 
 Does this help 
 
 ?barplot notes
 
 height: either a vector or matrix of values describing the bars
 which
  make up the plot.  If 'height' is a vector, the plot
  consists of a sequence of rectangular bars with heights
  given by the values in the vector.  If 'height' is a
  matrix and 'beside' is 'FALSE' then each bar of the plot
  corresponds to a column of 'height', with the values in
  the column giving the heights of stacked sub-bars making
  up the bar.  If 'height' is a matrix and 'beside' is
  'TRUE', then the values in each column are juxtaposed
  rather than stacked.
 
 
  
 
   
 
 -Original Message-
 From: T Petersen [mailto:[EMAIL PROTECTED]
 Sent: Friday, 18 February 2005 1:35 PM
 To: Kevin Wang
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Barplot - Can't figure it out
 
 
 Ups, it should of course be barplot() in my mail, not boxplot:-)
 
 Kevin Wang wrote:
 

 
 
 
 Hi,
 
 T Petersen wrote:
 
  
 
   
 
 Hi,
 
 I have two catagorical vectors like this;
 
 x = c(1, 2, 4, 2, 1)
 y = c(2, 4, 2 ,4, 1)
 
 I want to set up a barplot with the catagories 1-4 

 
 
 
 horizontally  and 

 
 
 
 number of occurances vertically for each vector x,y. I've tried
 
 boxplot(table(x,y), beside=T)
 
 and
 
 boxplot(c(x,y), beside=T)

 
 
 
 Have you tried barplot(), instead of boxplot()???
 
 Cheers,
 
 Kev
 
  
 
   
 
 __
 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
 

 
 
 
 __
 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
 
  
 
   
 
 __
 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
 
 
 
 Petr Pikal
 [EMAIL PROTECTED]
 
 __
 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
 
   
 
 
 __
 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

Petr Pikal
[EMAIL PROTECTED]

__
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


Re: [R] Barplot - Can't figure it out

2005-02-18 Thread T Petersen
Yeah, that's it. I have to catagorize the data AND tell R how many 
catagories there are. It works perfectly now and I've learned some 
more:-D Great.


Achim Zeileis wrote:
On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote:
 

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?
   

If x and y are categorical variables, you should tell R so (i.e.,
convert to a factor) and if both should have the same categories (i.e.,
levels) you can supply this information as well:
R x - factor(x, levels = 2:5)
R y - factor(y, levels = 2:5)
Then, table() knows which categories to use:
R rbind(x = table(x), y = table(y))
 2 3 4 5
x 0 6 4 0
y 4 0 1 5
and also the barplot() call given above will do the right thing.
Z
 

Petr Pikal wrote:
   

Hi
If I understand correctly
barplot(rbind(table(x), table(y)), beside=T)
does what you want.
Cheers
Petr

On 18 Feb 2005 at 7:51, T Petersen wrote:

 

Almost. Catagories aren't stacked - I would like to see that x has 2
instances of 1 while y has 1 instance of 1. What's more, there
   

arenow TWO distinct barplots - the left one shows x, while the right
oneshows y. I could live with that, but what I'd ideally want is to
havex and y beside each other for EACH catagory - so for catagory
1 youcould see taht there are more x's than y's (two x's versus
one y). Butthanks for the help
 

Mulholland, Tom wrote:
  

   

barplot(matrix(c(x,y),ncol = 2),beside=T)
Does this help 

?barplot notes
height: either a vector or matrix of values describing the bars
 

which make up the plot.  If 'height' is a vector, the plot
 

   consists of a sequence of rectangular bars with heights
   given by the values in the vector.  If 'height' is a
 

matrix and 'beside' is 'FALSE' then each bar of the plot
 

   corresponds to a column of 'height', with the values in
 

the column giving the heights of stacked sub-bars making
up the bar.  If 'height' is a matrix and 'beside' is
'TRUE', then the values in each column are juxtaposed
rather than stacked.
 




 

-Original Message-
From: T Petersen [mailto:[EMAIL PROTECTED]
Sent: Friday, 18 February 2005 1:35 PM
To: Kevin Wang
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Barplot - Can't figure it out
Ups, it should of course be barplot() in my mail, not boxplot:-)
Kevin Wang wrote:
 

  

   

Hi,
T Petersen wrote:
   



 

Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 
 

  

   

horizontally  and 
 

  

   

number of occurances vertically for each vector x,y. I've tried
boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
 

  

   

Have you tried barplot(), instead of boxplot()???
Cheers,
Kev
   



 

__
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

 

  

   

__
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



 

__
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
  

   

Petr Pikal
[EMAIL PROTECTED]
__
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

 

__
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
   

__
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
 

__
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


Re: [R] Barplot - Can't figure it out

2005-02-18 Thread Adaikalavan Ramasamy
Here is a generalisation of the function that others have suggested to
take take more than 2 vectors.

my.barplot - function(...){

  my.list - list(...)
  lev - sort( unique( unlist(my.list) ) )
  tmp - t(sapply( my.list, function(v) table(factor(v, levels=lev))) )
  barplot(tmp, beside=T)

}

w - c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4)
x - c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2)
y - c(1, 2, 3, 0, 5, 0, 1, 2, 1, 2)
z - sample( c(w,x,y,z), 50, replace=TRUE )

my.barplot( w, x, y, z )


Regards, Adai


On Fri, 2005-02-18 at 14:00 +0100, T Petersen wrote:
 Yeah, that's it. I have to catagorize the data AND tell R how many 
 catagories there are. It works perfectly now and I've learned some 
 more:-D Great.
 
 
 
 Achim Zeileis wrote:
 
 On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote:
 
   
 
 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?
 
 
 
 If x and y are categorical variables, you should tell R so (i.e.,
 convert to a factor) and if both should have the same categories (i.e.,
 levels) you can supply this information as well:
 
 R x - factor(x, levels = 2:5)
 R y - factor(y, levels = 2:5)
 
 Then, table() knows which categories to use:
 
 R rbind(x = table(x), y = table(y))
   2 3 4 5
 x 0 6 4 0
 y 4 0 1 5
 
 and also the barplot() call given above will do the right thing.
 Z
 
   
 
 Petr Pikal wrote:
 
 
 
 Hi
 
 If I understand correctly
 
 barplot(rbind(table(x), table(y)), beside=T)
 
 does what you want.
 
 Cheers
 Petr
 
 
 
 On 18 Feb 2005 at 7:51, T Petersen wrote:
 
  
 
   
 
 Almost. Catagories aren't stacked - I would like to see that x has 2
 instances of 1 while y has 1 instance of 1. What's more, there
 
 
 arenow TWO distinct barplots - the left one shows x, while the right
 oneshows y. I could live with that, but what I'd ideally want is to
 havex and y beside each other for EACH catagory - so for catagory
 1 youcould see taht there are more x's than y's (two x's versus
 one y). Butthanks for the help
   
 
 Mulholland, Tom wrote:
 

 
 
 
 barplot(matrix(c(x,y),ncol = 2),beside=T)
 
 Does this help 
 
 ?barplot notes
 
 height: either a vector or matrix of values describing the bars
   
 
 which make up the plot.  If 'height' is a vector, the plot
   
 
 consists of a sequence of rectangular bars with heights
 given by the values in the vector.  If 'height' is a
   
 
 matrix and 'beside' is 'FALSE' then each bar of the plot
   
 
 corresponds to a column of 'height', with the values in
   
 
 the column giving the heights of stacked sub-bars making
 up the bar.  If 'height' is a matrix and 'beside' is
 'TRUE', then the values in each column are juxtaposed
 rather than stacked.
   
 
 
 
  
 
   
 
 -Original Message-
 From: T Petersen [mailto:[EMAIL PROTECTED]
 Sent: Friday, 18 February 2005 1:35 PM
 To: Kevin Wang
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Barplot - Can't figure it out
 
 
 Ups, it should of course be barplot() in my mail, not boxplot:-)
 
 Kevin Wang wrote:
 
   
 

 
 
 
 Hi,
 
 T Petersen wrote:
 
 
 
  
 
   
 
 Hi,
 
 I have two catagorical vectors like this;
 
 x = c(1, 2, 4, 2, 1)
 y = c(2, 4, 2 ,4, 1)
 
 I want to set up a barplot with the catagories 1-4 
   
 

 
 
 
 horizontally  and 
   
 

 
 
 
 number of occurances vertically for each vector x,y. I've tried
 
 boxplot(table(x,y), beside=T)
 
 and
 
 boxplot(c(x,y), beside=T)
   
 

 
 
 
 Have you tried barplot(), instead of boxplot()???
 
 Cheers,
 
 Kev
 
 
 
  
 
   
 
 __
 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
 
   
 

 
 
 
 __
 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
 
 
 
  
 
   
 
 __
 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

 
 
 
 Petr

[R] Barplot - Can't figure it out

2005-02-17 Thread T Petersen
Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 horizontally  and 
number of occurances vertically for each vector x,y. I've tried

boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
among others, but can't get it to work...Any ideas? I'd apppreciate any help
__
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


Re: [R] Barplot - Can't figure it out

2005-02-17 Thread Kevin Wang
Hi,
T Petersen wrote:
Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 horizontally  and 
number of occurances vertically for each vector x,y. I've tried

boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
Have you tried barplot(), instead of boxplot()???
Cheers,
Kev
--
Ko-Kang Kevin Wang
PhD Student
Centre for Mathematics and its Applications
Building 27, Room 1004
Mathematical Sciences Institute (MSI)
Australian National University
Canberra, ACT 0200
Australia
Homepage: http://wwwmaths.anu.edu.au/~wangk/
Ph (W): +61-2-6125-2431
Ph (H): +61-2-6125-7407
Ph (M): +61-40-451-8301
__
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


Re: [R] Barplot - Can't figure it out

2005-02-17 Thread T Petersen
Ups, it should of course be barplot() in my mail, not boxplot:-)
Kevin Wang wrote:
Hi,
T Petersen wrote:
Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 horizontally  and 
number of occurances vertically for each vector x,y. I've tried

boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)

Have you tried barplot(), instead of boxplot()???
Cheers,
Kev
__
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


RE: [R] Barplot - Can't figure it out

2005-02-17 Thread Mulholland, Tom
barplot(matrix(c(x,y),ncol = 2),beside=T)

Does this help 
 
?barplot notes

height: either a vector or matrix of values describing the bars which
  make up the plot.  If 'height' is a vector, the plot consists
  of a sequence of rectangular bars with heights given by the
  values in the vector.  If 'height' is a matrix and 'beside'
  is 'FALSE' then each bar of the plot corresponds to a column
  of 'height', with the values in the column giving the heights
  of stacked sub-bars making up the bar.  If 'height' is a
  matrix and 'beside' is 'TRUE', then the values in each column
  are juxtaposed rather than stacked.


 -Original Message-
 From: T Petersen [mailto:[EMAIL PROTECTED]
 Sent: Friday, 18 February 2005 1:35 PM
 To: Kevin Wang
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Barplot - Can't figure it out
 
 
 Ups, it should of course be barplot() in my mail, not boxplot:-)
 
 Kevin Wang wrote:
 
  Hi,
 
  T Petersen wrote:
 
  Hi,
 
  I have two catagorical vectors like this;
 
  x = c(1, 2, 4, 2, 1)
  y = c(2, 4, 2 ,4, 1)
 
  I want to set up a barplot with the catagories 1-4 
 horizontally  and 
  number of occurances vertically for each vector x,y. I've tried
 
  boxplot(table(x,y), beside=T)
 
  and
 
  boxplot(c(x,y), beside=T)
 
 
  Have you tried barplot(), instead of boxplot()???
 
  Cheers,
 
  Kev
 
 
 __
 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


__
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


Re: [R] Barplot - Can't figure it out

2005-02-17 Thread T Petersen
Almost. Catagories aren't stacked - I would like to see that x has 2 
instances of 1 while y has 1 instance of 1. What's more, there are 
now TWO distinct barplots - the left one shows x, while the right one 
shows y. I could live with that, but what I'd ideally want is to have x 
and y beside each other for EACH catagory - so for catagory 1 you 
could see taht there are more x's than y's (two x's versus one y). But 
thanks for the help

Mulholland, Tom wrote:
barplot(matrix(c(x,y),ncol = 2),beside=T)
Does this help 

?barplot notes
height: either a vector or matrix of values describing the bars which
 make up the plot.  If 'height' is a vector, the plot consists
 of a sequence of rectangular bars with heights given by the
 values in the vector.  If 'height' is a matrix and 'beside'
 is 'FALSE' then each bar of the plot corresponds to a column
 of 'height', with the values in the column giving the heights
 of stacked sub-bars making up the bar.  If 'height' is a
 matrix and 'beside' is 'TRUE', then the values in each column
 are juxtaposed rather than stacked.
 

-Original Message-
From: T Petersen [mailto:[EMAIL PROTECTED]
Sent: Friday, 18 February 2005 1:35 PM
To: Kevin Wang
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Barplot - Can't figure it out
Ups, it should of course be barplot() in my mail, not boxplot:-)
Kevin Wang wrote:
   

Hi,
T Petersen wrote:
 

Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4 
   

horizontally  and 
   

number of occurances vertically for each vector x,y. I've tried
boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
   

Have you tried barplot(), instead of boxplot()???
Cheers,
Kev
 

__
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

   

__
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
 

__
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