[R] trajectory plot (growth curve)
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Aug 23 22:16:49 CEST 2010
On Mon, Aug 23, 2010 at 3:58 PM, Lei Liu <liulei at virginia.edu> wrote:
> Hi there,
>
> I want to make trajectory plots for data as follows:
>
> ID time y
> 1 1 1.4
> 1 2 2.0
> 1 3 2.5
> 2 1.5 2.3
> 2 4 4.5
> 2 5.5 1.6
> 2 6 2.0
>
> ...
>
> That is, I will plot a growth curve for each subject ID, with y in the y
> axis, and time in the x axis. I would like to have all growth curves in the
> same plot. Is there a simple way in R to do it? Thanks a lot!
>
Try this.
Lines <- "ID time y
1 1 1.4
1 2 2.0
1 3 2.5
2 1.5 2.3
2 4 4.5
2 5.5 1.6
2 6 2.0"
library(zoo)
# z <- read.zoo("myfile.dat", header = TRUE, split = 1, index = 2)
z <- read.zoo(textConnection(Lines), header = TRUE, split = 1, index = 2)
plot(z) # each in separate panel
plot(z, col = 1:2) # all on same plot in different colors
More information about the R-help
mailing list