ISS608-VAA
  • ✌️ Hands-on Exercises
    • Hands-on Exercise 1
    • Hands-on Exercise 2
    • Hands-on Exercise 3a
    • Hands-on Exercise 3b
    • Hands-on Exercise 4a
    • Hands-on Exercise 4b
    • Hands-on Exercise 4c
    • Hands-on Exercise 4d
    • Hands-on Exercise 5
    • Hands-on Exercise 6
    • Hands-on Exercise 7a
    • Hands-on Exercise 7b
    • Hands-on Exercise 7c
    • Hands-on Exercise 8
    • Hands-on Exercise 9
    • Hands-on Exercise 10
  • πŸ‘¨πŸ»β€πŸ«In-class Exercises
    • In-class Exercise 1
    • In-class Exercise 6
  • 🏠 Take-home Exercises
    • Take-home Exercise 1
    • Take-home Exercise 2
    • Take-home Exercise 3
    • Take-home Exercise 4
  • Home
  • My VAA Journey
  • Dictionary

In-class Exercise 6

  • Show All Code
  • Hide All Code

  • View Source

Time on the Horizon: ggHoriPlot methods

Author

Victoria Neo

Published

February 24, 2024

Modified

February 24, 2024

code block
pacman::p_load(ggHoriPlot, ggthemes, tidyverse)
code block
averp <- read_csv("data/AVERP.csv") %>%
  mutate(`Date` = dmy(`Date`))
code block
averp %>% 
  filter(Date >= "2018-01-01") %>%
  ggplot() +
  geom_horizon(aes(x = Date, y=Values), 
               origin = "midpoint", 
               horizonscale = 6)+
  facet_grid(`Consumer Items`~.) +
    theme_few() +
  scale_fill_hcl(palette = 'RdBu') +
  theme(panel.spacing.y=unit(0, "lines"), strip.text.y = element_text(
    size = 5, angle = 0, hjust = 0),
    legend.position = 'none',
    axis.text.y = element_blank(),
    axis.text.x = element_text(size=7),
    axis.title.y = element_blank(),
    axis.title.x = element_blank(),
    axis.ticks.y = element_blank(),
    panel.border = element_blank()
    ) +
    scale_x_date(expand=c(0,0), date_breaks = "3 month", date_labels = "%b%y") +
  ggtitle('Average Retail Prices of Selected Consumer Items (Jan 2018 to Dec 2022)')

Source Code
---
title: 'In-class Exercise 6'
subtitle: '[Time on the Horizon: ggHoriPlot methods](https://r4va.netlify.app/chap20)'
author: "Victoria Neo"
date: "02/24/2024"
date-modified: "last-modified"
format:
  html:
    code-fold: true
    code-summary: code block
    code-tools: true
    code-copy: true
execute:
  eval: true
  echo: true
  freeze: true
  warning: false
  message: false
---

```{r}
pacman::p_load(ggHoriPlot, ggthemes, tidyverse)
```

```{r}
averp <- read_csv("data/AVERP.csv") %>%
  mutate(`Date` = dmy(`Date`))
```

```{r}
#| fig-width: 12
#| fig-height: 10
averp %>% 
  filter(Date >= "2018-01-01") %>%
  ggplot() +
  geom_horizon(aes(x = Date, y=Values), 
               origin = "midpoint", 
               horizonscale = 6)+
  facet_grid(`Consumer Items`~.) +
    theme_few() +
  scale_fill_hcl(palette = 'RdBu') +
  theme(panel.spacing.y=unit(0, "lines"), strip.text.y = element_text(
    size = 5, angle = 0, hjust = 0),
    legend.position = 'none',
    axis.text.y = element_blank(),
    axis.text.x = element_text(size=7),
    axis.title.y = element_blank(),
    axis.title.x = element_blank(),
    axis.ticks.y = element_blank(),
    panel.border = element_blank()
    ) +
    scale_x_date(expand=c(0,0), date_breaks = "3 month", date_labels = "%b%y") +
  ggtitle('Average Retail Prices of Selected Consumer Items (Jan 2018 to Dec 2022)')
```