Counting distinct observations

airlines %>%
  count(carrier) %>% 
  filter(n > 1)
## # A tibble: 0 x 2
## # ... with 2 variables: carrier <chr>, n <int>
airports %>%
  count(faa) %>%
  filter(n > 1)
## # A tibble: 0 x 2
## # ... with 2 variables: faa <chr>, n <int>

Heat map: destination by airline

flights %>% 
  filter(distance < 300) %>%
  count(dest, carrier) %>%
  left_join(airlines, by = "carrier") %>%
  rename(carrier_name = name) %>%
  left_join(airports, by = c("dest" = "faa")) %>%
  rename(airport_name = name) %>% 
  ggplot() +
  geom_raster(aes(airport_name, carrier_name, fill = n)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Copyright © 2018 Kirill Müller. Licensed under CC BY-NC 4.0.