Plotting Heart Rate Change Over Time

I'm trying to figure out a way to plot heart rate data over time using a line graph or something. In the photos I just have a snip-it of entire data frame 0-30, just to figure out a way to do it. The problem is each one of my time variables is its own variable (0,1,2,3, etc) As you can see, I tried pivoting the data but that not helping much either. I attached a very basic sketch of what I'm trying to achieve here. Any help would be greatly appreciated.

I attached the data to the link below


Screenshots are not very useful, Can you please share a small part of the data set in a copy-paste friendly format?

In case you don't know how to do it, there are many options, which include:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

Ideally, to help us help you, you should prepare a reproducible example (reprex) illustrating your issue. Please have a look at this guide, to see how to create one:


That link only works in your own computer other people can't see it.

Please follow advice and share some sample data in a copy paste friendly format.

heartrate <- tibble::tribble(
                       ~V1,  ~V2,  ~V3,  ~V4,  ~V5,  ~V6,  ~V7,  ~V8,  ~V9, ~V10, ~V11, ~V12,
               "ID Number",   0L,   1L,   2L,   3L,   4L,   5L,   6L,   7L,   8L,   9L,  10L,
                   "CD-01",  66L,  66L,  64L,  64L,  58L,  58L,  58L,  57L,  56L,  56L,  57L,
                   "SS-02",  85L,  84L,  83L,  81L,  80L,  79L,  78L,  78L,  79L,  80L,  80L,
                   "CD-03", 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L,
                   "CD-04", 115L, 115L, 114L, 114L, 114L, 114L, 112L, 111L, 110L, 109L, 109L,
                  "SS-101",  63L,  63L,  63L,  63L,  77L,  78L,  80L,  77L,  76L,  67L,  67L,
                   "CD-05",  84L,  63L,  62L,  62L,  63L,  58L,  58L,  54L,  62L,  66L,  66L,
                  "SS-102",  49L,  48L,  46L,  46L,  45L,  46L,  45L,  45L,  45L,  45L,  46L,
                  "CD-103",  70L,  69L,  68L,  68L,  69L,  69L,  69L,  69L,  68L,  69L,  70L,
                   "CD-06",  83L,  84L,  84L,  84L,  84L,  84L,  82L,  82L,  82L,  82L,  81L,
                   "SS-08",  79L,  78L,  67L,  67L,  68L,  62L,  62L,  62L,  63L,  72L,  72L,
                   "CD-09", 240L, 202L, 141L, 106L,  89L,  74L,  71L,  71L,  71L,  72L,  74L,
                   "SS-10",  78L,  78L,  77L,  76L,  75L,  75L,  75L,  75L,  76L,  76L,  76L,
                  "CD-105",  66L,  66L,  66L,  66L,  66L,  66L,  67L,  67L,  67L,  67L,  68L,
                   "CD-11",  66L,  66L,  76L,  76L,  76L,  77L,  75L,  75L,  75L,  75L,  76L

Does that work? The "L" isn't supposed to be there but I think it will automatically be removed when you run it

The L means that they are integers

This is how to do the plot you are describing


# Sample data in a copy/paste friendly format
heartrate <- data.frame(
  stringsAsFactors = FALSE,
       check.names = FALSE,
       `ID Number` = c("CD-01","SS-02","CD-03",
               `0` = c(66L,85L,103L,115L,63L,84L,
               `1` = c(66L,84L,103L,115L,63L,63L,
               `2` = c(64L,83L,103L,114L,63L,62L,
               `3` = c(64L,81L,103L,114L,63L,62L,
               `4` = c(58L,80L,103L,114L,77L,63L,
               `5` = c(58L,79L,103L,114L,78L,58L,
               `6` = c(58L,78L,103L,112L,80L,58L,
               `7` = c(57L,78L,103L,111L,77L,54L,
               `8` = c(56L,79L,103L,110L,76L,62L,
               `9` = c(56L,80L,103L,109L,67L,66L,
              `10` = c(57L,80L,103L,109L,67L,66L,

# Relevant code
heartrate %>% 
    pivot_longer(cols = -`ID Number`, names_to = "time", values_to = "HR") %>% 
    mutate(time = as.numeric(time)) %>% 
    ggplot(aes(x = time, y = HR, linetype = `ID Number`)) +

Created on 2021-09-04 by the reprex package (v2.0.1)

1 Like

You are the goat. Thank you. I'm going to mess with this over the next couple days. I might have a question or two. Thanks again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.