[R] Change line colors based on data values in Lattice

Liu, Andrew Andrew_Liu at troweprice.com
Mon Jan 30 22:08:46 CET 2012


Say I have

x = seq(1, 40)
y = seq(1, 40)^2
g = rep(c("A", "B", "A", "B"), each = 10)
xyplot(y~x, groups = g, type = 'l')


Is there a way to have a single line and have it be one color when g == "A", and another when g == "B"?

Thanks!

Regards,
Andrew Liu
Fixed Income | Investment Fellow
T. Rowe Price
100 E. Pratt St, BA-0735
Baltimore, MD 21202
* Office: (410) 345-2750
* E-mail: andrew_liu at troweprice.com<mailto:andrew_liu at troweprice.com>
* Please consider the environment before printing this e-mail.




T. Rowe Price (including T. Rowe Price Group, Inc. and its affiliates) and its associates do not provide legal or tax advice.  Any tax-related discussion contained in this e-mail, including any attachments, is not intended or written to be used, and cannot be used, for the purpose of (i) avoiding any tax penalties or (ii) promoting, marketing, or recommending to any other party any transaction or matter addressed herein.  Please consult your independent legal counsel and/or professional tax advisor regarding any legal or tax issues raised in this e-mail.

The contents of this e-mail and any attachments are intended solely for the use of the named addressee(s) and may contain confidential and/or privileged information. Any unauthorized use, copying, disclosure, or distribution of the contents of this e-mail is strictly prohibited by the sender and may be unlawful. If you are not the intended recipient, please notify the sender immediately and delete this e-mail.



More information about the R-help mailing list