How to plot time series with multiple sample rows

I've created something called a reprex (short for reproducible example) that I think matches the specs you're describing (see the guide on how to do one yourself here).

I'm using the tidyverse package (specifically tibble to create the dummy data, which you won't need to do since you have the actual data, and ggplot2 for the plotting the geom_line()) to do this, but I'm sure the same could be done in a variety of ways.

tibbles and data tables (using the data.table package) are enhanced data frames, and, no, you don't need to use either of them specifically to accomplish this.

library(tidyverse)
dat <- tibble::tribble(
  ~sample_id, ~time, ~value,
     "gghjk",   0.5,    0.8,
     "gghjk",     1,      2,
     "gghjk",   1.5,    2.1,
     "gghjk",     2,    2.2,
     "gghjk",   2.5,      3,
     "gghjk",     3,    3.2,
     "gghjk",   3.5,    3.4,
     "gghjk",     4,    3.5,
     "gghjk",   4.5,    3.6,
     "gghjk",     5,      4,
     "lknnm",   0.5,    0.3,
     "lknnm",     1,    1.5,
     "lknnm",   1.5,    1.6,
     "lknnm",     2,    1.7,
     "lknnm",   2.5,    2.5,
     "lknnm",     3,    2.7,
     "lknnm",   3.5,    2.9,
     "lknnm",     4,      3,
     "lknnm",   4.5,    3.1,
     "lknnm",     5,    3.5
  )

dat %>%
  ggplot(aes(x = time, y = value, group = sample_id)) +
  geom_line(aes(colour = sample_id))

Created on 2021-04-08 by the reprex package (v1.0.0)

Hope this helps. Note that I'm grouping by which sample, rather than in groups of ten rows, since that sounds like it's your actual goal.

P.S. For more on working with time series in R, I highly recommend checking out the tsibble package, which is part of the "tidyverts" ecosystem:

1 Like