[R] Plotting symbols and colors based upon data values

David Winsemius dwinsemius at comcast.net
Sun Mar 13 04:38:46 CET 2011


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



More information about the R-help mailing list