Re: [R] Plotting symbols and colors based upon data values

From: Mark Linderman <mark.linderman_at_gmail.com>
Date: Sun, 13 Mar 2011 20:51:49 -0400

David, thank you for your quick reply. I spent a few minutes getting your command to work with some sparse synthetic data, and then spent several hours trying to figure out why my data didn't work (at least for symbols, colors look okay). I have massaged my data to where it is practically indistinguishable from the synthetic data - yet it still doesn't work. Attached are the two data files that can be plotted as follows:

broken = read.table("broken.table",header=TRUE) works = read.table("works.table",header=TRUE) xyplot(Y ~ X | A, data=works, pch=works$C , col=works$B) xyplot(Y ~ X | A, data=broken, pch=broken$C , col=broken$B)

Only difference I see is that my data is largely sorted by $C whereas the working data frame is not. Not sure why that would make a difference.

Thanks again for your help!
Mark

> head(broken)

          X Y A B C

1 0.3476158 0.5334874 Cat A   red 1
2 0.5692598 0.3205288 Cat A   red 1
3 0.5879649 0.3593725 Cat A black 1
4 0.9642691 0.9242240 Cat A black 1
5 0.5303471 0.7964391 Cat A   red 1
6 0.9998770 0.1722618 Cat A black 1


> head(works)
X Y A B C 1 0.55722499 31 cat D yellow 2 2 0.75100600 32 cat B red 5 3 0.21665005 33 cat C green 4 4 0.01201102 34 cat B red 3

5 0.78503588 35 cat B black 2
6 0.53589896 36 cat D blue 5
-----Original Message-----
From: David Winsemius [mailto:dwinsemius_at_comcast.net] Sent: Saturday, March 12, 2011 10:39 PM
To: Mark Linderman
Cc: r-help_at_r-project.org
Subject: Re: [R] Plotting symbols and colors based upon data values

On Mar 12, 2011, at 7:57 PM, Mark Linderman wrote:

> I am new to R and am sure this is simple, but I been unable to find a
> solution.
>
> I have 5 columns of data labeled "X", "Y", "A","B","C". I can easily
> xyplot(Y ~ X | A) but I want the colors of the symbols to be based
> upon the
> values of B and the shape of the symbols to be determined by C.
> There are
> approximately four distinct values of B and C (say "b1","b2","b3","b4"
> and "c1","c2","c3","c4", respectively)
>
No data to check it against (despite the request for such that accompanies every posting) but see if this give the desired result:

xyplot(Y ~ X | A, data=dfrm2, pch=dfrm2$C , col=dfrm2$B)

> Either a solution or a pointer to a specific reference/example is
> greatly appreciated.

There are many in the contributed documentation as well as in Sarkar's book website and in the graphics galleries. As you suggested, it's pretty basic stuff since you are benefiting from Sarkar's effort to carry over some of the argument names from basic graphics. The one "trick" is to not rely on the argument being assumed to come from the environment of the `data` argument.

-- 

David Winsemius, MD
West Hartford, CT

______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Mon 14 Mar 2011 - 04:15:02 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 14 Mar 2011 - 04:20:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive