Hikes I've Completed

Here I will plot some of the hikes I have done as elevation (from sea level) versus distance. I was inspired by this Reddit post

Today’s code was great practice with

  • geom_segment
  • geom_label_repel

and using xlim and ylim to expand the plot.

library(ggrepel)
library(tidyverse)
library(readxl)
df_info <- read_excel("hikes.xlsx", sheet = "info")
df_info %>% print()
## # A tibble: 9 x 6
##   Region    trail                distance trailhead elevation  peak
##   <chr>     <chr>                   <dbl>     <dbl>     <dbl> <dbl>
## 1 Tahoe     Mt Tallac                 5.1      6445      3290  9735
## 2 Tahoe     Flume                     6.4      6980      1420  8400
## 3 Tahoe     Mt Rose                   5.4      8388      2388 10776
## 4 Tahoe     Relay Peak                4.7      8388      1515  9903
## 5 Tahoe     Donner Peak               1.9      6175       882  7057
## 6 Yosemite  Four-Mile                 4.7      4000      3200  7200
## 7 Yosemite  Nevada Falls              4.4      4000      2191  6191
## 8 Yosemite  Upper Yosemite Falls      3.6      4000      3175  7175
## 9 Mt Diablo Waterfall                 4         374      1709  2083
df_info %>%
  mutate(start = 0) %>% #the first x-value for each line segment
  ggplot() +
  geom_segment(aes(x = start, y = trailhead, 
                   xend = distance, yend = peak, 
                   color = Region)) +
  geom_label_repel(aes(x = distance, y = peak, 
                       color = Region,
                       label = trail),
                   box.padding = 1,
                   segment.color = "grey50",
                   segment.size = 0.5) +
  geom_point(aes(x = distance, y = peak, color = Region), size = 5) +
  labs(title = "Hikes I've Completed",
       subtitle = "Derek Sollberger",
       caption = "2010 to 2019",
       x = "One-Way Distance (in miles)",
       y = "Elevation (in feet)") +
  theme_minimal() +
  xlim(0,8) +
  ylim(0, 15000)

Related