[R] problem with plotting table

Bernardo Rangel Tura tura at centroin.com.br
Wed Nov 28 09:13:57 CET 2007


On Tue, 2007-11-27 at 13:01 -0500, Carlos Gershenson wrote:
> Hi all,
> 
> Let us have:
> 
> x<-1:10
> y<-x/2
> plot(table(x), type="p")
> points(table(y), pch=2)
> 
> 
> Why does the last command plots the values of table(y) using the x  
> coordinates of table(x)???
> Am I doing something wrong?
> What would be a way of plotting the points of table(y) on their place?
> 
> #this problem also occurs with:
> plot(table(y), type="p")
> points(table(x), pch=2)
> 
> 
> Thank you very much,
> Carlos


Hi Carlos 

In your command plot(table(y), type="p"), you plot a numeric part of
table(y), in this case:

y
0.5   1 1.5   2 2.5   3 3.5   4 4.5   5 
  1   1   1   1   1   1   1   1   1   1

So you plot the number 1 always. Same for table (x).

Have two possible solutions:

plot(as.numeric(names(table(x))), type="p")
points(as.numeric(names(table(y))), pch=2)


OR

x<-1:10
y<-x/2
plot(x, type="p")
points(y, pch=2)

If you need more help send a mail



-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list