[R] x,y plot question (two sets of labels)
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Thu Jan 21 01:46:04 CET 2010
Tena koe Jonathan
There are lots of ways - using base graphics or lattice or ggplot. As a
start, using base graphics:
plot(plothelpX, plothelpA2, col=factor(plothelpB))
points(plothelpX, plothelpA1, col=factor(plothelpB))
You'll also need the pch argument to plot and, presumably, xlab, ylab
and others.
For the key, check the help for legend:
?legend
HTH
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Jonathan Greenberg
> Sent: Thursday, 21 January 2010 12:54 p.m.
> To: r-help
> Subject: [R] x,y plot question (two sets of labels)
>
> I'm trying to figure out the best way to do a scatterplot
> using the following data as an example:
>
> plothelp_x=1:10
> plothelp_A1=sin(plothelp_x)
> plothelp_A2=tan(plothelp_x)
> plothelp_B=c("A","B","C","A","B","C","A","B","C","A")
>
> (note that all 4 of these vectors have 10 entries each)
>
> What I would like is to have two plots on the same graph:
>
> 1) plothelp_A1 vs. plothelp_x
> 2) plothelp_A2 vs. plothelp_x
>
> I want plot #1 to have a set symbol SHAPE (say, crosses) and
> plot #2 a different symbol shape (say, dots). On top of
> that, I want all points to be color coded based on
> plothelp_B, e.g. all As are black, all Bs are red, all Cs are
> blue; e.g a sin point with the letter "A" should be a black
> cross, a tan point with the letter C should be a red dot.
> Finally, I'd like two have TWO keys in the graph showing a)
> what the symbol shapes represent (e.g. cross=sin, dot=tan),
> and b) what the colors mean.
>
> Thanks for any help you can give me!
>
> --j
>
> --
>
> Jonathan A. Greenberg, PhD
> Postdoctoral Scholar
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> University of California, Davis One Shields Avenue The Barn,
> Room 250N Davis, CA 95616
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list