Mark Linderman
2011-Mar-13 00:57 UTC
[R] Plotting symbols and colors based upon data values
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) Either a solution or a pointer to a specific reference/example is greatly appreciated. Thanks, Mark [[alternative HTML version deleted]]
David Winsemius
2011-Mar-13 03:38 UTC
[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
Seemingly Similar Threads
- lattice xyplot symbols instead of colors and legend matching plot symbols or colors
- xyplot with different symbols and colors?
- Lattice, stripplot (xyplot), plotting data with median line, numeric x-axis
- altering identity column
- multiple lty on same panel in xyplot