library(dplyr)
library(ggplot2)
library(readr)

# prepare data
md <- read_csv("GOTOES_FIT-CSV_4284285070831056.csv") |> 
  select(timestamp, position_lat, position_long, altitude, heart_rate, 
         distance, speed, grade, gps_accuracy, calories) |> 
  mutate(distance.km=distance/1000, 
         grade.edited=case_when(grade < 15 ~ grade, TRUE ~ NA_real_), 
         segment=case_when(distance.km>=8.89 & distance.km <=108.82 ~ "B2GC", 
                           TRUE~ "non-B2GC")) |> 
  filter(speed <= 64.2)


# set range
z <- c(8.89, 108.82)

# make plot
ggplot(filter(md, distance.km<z[1]), aes(x=distance.km, y=heart_rate)) +
  geom_line(aes(color="grey")) +
  geom_line(data=filter(md, between(distance.km,z[1], z[2])), aes(color="darkred")) +
  geom_line(data=filter(md, distance.km>z[2]), color="grey") +
  scale_color_manual("segment", values = c("darkred", "grey"), 
                     labels = c("B2GC", "non-B2GC")) +
  coord_cartesian(ylim = c(60, 200)) +
  theme_linedraw()

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

ggplot(filter(md, distance.km<z[1]), aes(x=distance.km, y=heart_rate)) +
  geom_area(aes(fill="grey"), alpha=.7) +
  geom_area(data=filter(md, between(distance.km, z[1], z[2])), aes(fill="darkred"),
            alpha=.7) +
  geom_area(data=filter(md, distance.km>z[2]), fill="grey", alpha=.7) +
  scale_fill_manual("segment", values = c("darkred", "grey"),
                    labels = c("B2GC", "non-B2GC")) +
  coord_cartesian(ylim = c(60, 200)) +
  theme_linedraw()

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Created on 2023-09-09 with reprex v2.0.2