[R] Scatterplot question

Gabor Grothendieck ggrothendieck at myway.com
Thu Dec 9 19:01:08 CET 2004


 <judith.baltsar <at> gmx.de> writes:

: 
: Dear list members,
: I have a probably simple question concerning scatterplots: I want to 
: draw a plot with one X but several Y columns, so that every group 
: of samples gets a different symbol. My table looks like this:
: 
: X	Y1	Y2	Y3
: 1	1
: 2	3
: 3	5
: 4		7
: 5		9
: 6		11
: 7			13
: 8			15
: 
: Simple in Excel or StarOffice, but how do I do it in R?

If you already have this as a data frame or matrix then others
have already mentioned matplot.  If you are looking
for a quick way to get the data into that form in the first
place without manually padding it out with NAs then you could
represent them as time series and cbind them.  Assuming regularly
spaced time series you can use ts:

Y1 <- ts(c(1,3,5), start = 1)
Y2 <- ts(c(7,9,11), start = 4)
Y3 <- ts(c(13,15), start = 7)
Y <- cbind(Y1, Y2, Y3)

plot(Y, plot.type = "single", col = rainbow(3))
# or
matplot(1:8, Y)




More information about the R-help mailing list