Skip to content

Instantly share code, notes, and snippets.

@juliasilge
Created November 9, 2022 01:35
Show Gist options
  • Save juliasilge/6d21e6bfd2a8d73c9cde43a181191180 to your computer and use it in GitHub Desktop.
Save juliasilge/6d21e6bfd2a8d73c9cde43a181191180 to your computer and use it in GitHub Desktop.
#TidyTuesday radio stations
library(tidyverse)
theme_set(silgelib::theme_plex())
radio_stations <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-11-08/state_stations.csv')
#> Rows: 17186 Columns: 6
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (6): call_sign, frequency, city, licensee, format, state
#> 
#> ℹ 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.

radio_stations %>%
    separate(frequency, c("frequency", "modulation"), sep = " ") %>%
    filter(modulation %in% c("AM", "FM")) %>%
    mutate(modulation = if_else(
        modulation == "AM", 
        "AM band (frequency in kHz)", 
        "FM band (frequency in MHz)")
    ) %>%
    mutate(frequency = parse_number(frequency)) %>%
    ggplot(aes(frequency, fill = modulation)) +
    geom_histogram(bins = 15, alpha = 0.8, show.legend = FALSE) +
    facet_wrap(vars(modulation), scales = "free") +
    scale_fill_brewer(palette = "Accent") +
    labs(y = "Number of radio stations", x = NULL,
         title = "How are radio station frequencies distributed in the US?")
#> Warning: Expected 2 pieces. Additional pieces discarded in 1 rows [8334].
#> Warning: Expected 2 pieces. Missing pieces filled with `NA` in 509 rows [1496,
#> 1713, 2056, 4793, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321,
#> 11322, 11323, 11324, 11325, 11326, 11327, 11328, ...].

Created on 2022-11-08 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment