[R] trajectory plot (growth curve)

Kingsford Jones kingsfordjones at gmail.com
Mon Aug 23 23:25:48 CEST 2010


and some more options...

dat <- structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L),
  .Label = c("1", "2"), class = "factor"),
  time = c(1, 2, 3, 1.5, 4, 5.5, 6),
  y = c(1.4, 2, 2.5, 2.3, 4.5, 1.6, 2)),
  .Names = c("ID", "time", "y"),
  row.names = c(NA, -7L), class = "data.frame")

library(lattice)
xyplot(y ~ time|ID, data = dat, type = 'l')
xyplot(y ~ time, data = dat, group = ID, type = 'l')

library(ggplot2)
qplot(time, y, data = dat, facets = .~ID, geom = 'line')
qplot(time, y, data = dat, group = ID, color = ID, geom = 'line')


hth,

Kingsford Jones

On Mon, Aug 23, 2010 at 1: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!
>
> Lei Liu
> Associate Professor
> Division of Biostatistics and Epidemiology
> Department of Public Health Sciences
> University of Virginia School of Medicine
>
> http://people.virginia.edu/~ll9f/
>
> ______________________________________________
> 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