---
# System prepended metadata

title: ptt_r_090923

---

``` r
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()
```
![](https://hackmd.io/_uploads/r1-E1slJ6.png)


``` r
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()
```

![](https://hackmd.io/_uploads/H1Od1sekp.png)

<sup>Created on 2023-09-09 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
