tidytuesday 2020 Semana 02

Australian Fires

Autor

Lucas Carmo

Publicado

2020 - 01 - 07

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.1      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(here)
here() starts at /Users/lucas/Dev/quarto-blog
library(lubridate)
Loading required package: timechange

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union

Data

temperature <-
    readr::read_csv(
        "https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/temperature.csv"
    )
Rows: 528278 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (3): city_name, temp_type, site_name
dbl  (1): temperature
date (1): date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Wrangle

city_temp <- temperature %>%
    filter(
        city_name %in% c("MELBOURNE", "PERTH", "SYDNEY", "BRISBANE"),
        date >= as_date("1970-01-01"),
        date < as_date("2019-01-01")
    ) %>%
    group_by(city_name,
        year = year(date),
        month = month(date, label = TRUE)
    ) %>%
    summarise(temp = mean(temperature, na.rm = TRUE))
`summarise()` has grouped output by 'city_name', 'year'. You can override using
the `.groups` argument.

Plot

ggplot(city_temp, aes(
    x = year,
    y = forcats::fct_rev(month),
    fill = temp
    )
) +
    geom_raster() +
    scale_fill_viridis_c(option = "inferno") +
    theme_minimal() +
    theme(
        text = element_text(family = "Fira Sans"),
        panel.grid = element_blank(),
        plot.caption = element_text(hjust = 0)
    ) +
    facet_wrap(~city_name) +
    labs(
        title = "Australian Cities Temperature Over Time",
        subtitle = "Melbourne has lower mean temperatures in comparison",
        y = "",
        x = "",
        fill = "Average \ntemperature \n(°C)",
        caption =
            "Data: Australian Bureau of Meteorology\nVis: Lucas C. L. do Carmo"
    )