Re: [R] (no subject)

From: Jim Lemon <>
Date: Mon, 24 Mar 2008 21:19:34 +1100

Donna Tucker wrote:
> Is there any way to use more than one color or shape in the same plot. I would like to make the points different colors for various levels of a variable. I have tried a simple 'if' statement in the plot command, but I get an error message. Here is what I have tried and the error message I get: > plot(test, if(test[,1]<8) col="steelblue2" else col="wheat2")Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differIn addition: Warning message:In if (test[, 1] < 8) col = "steelblue2" else col = "wheat2" : the condition has length > 1 and only the first element will be usedI know 'x' and 'y' lenghths do NOT differ. If I just do plot(test), it works perfectly. Is there any way to this?Thanks,Donna

Hi Donna,
What is happening is that you have passed two arguments to "plot" without naming them. The first one (test) is interpreted as the "x" coordinates, and the second one:

if(test[,1]<8) col="steelblue2" else col="wheat2"

finishes up as "steelblue2" if test[1,1] is less than 8 or "wheat2" if not. This is interpreted as the "y" coordinates. Unless you have only one element in test (and of course we can infer that you have more), those lengths will differ. What you can do is to specify that your second argument is meant to be a color vector like this:


Now of course I am assuming that "test" is a matrix or data frame with at least two columns. If it isn't, the above example will fall over and whinge.

 > How well do you know your celebrity gossip?

I'm sorry, but I can't help you at all with that.

Jim mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 24 Mar 2008 - 10:13:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 24 Mar 2008 - 10:30:23 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive