--- title: "Maps" author: "Prof. Eric A. Suess" format: html: self-contained: true --- ```{r} library(pacman) p_load(tidyverse, nasaweather) atmos # Atmospheric data. borders <- ungroup(borders) # Country borders, ungroup fixes a problem elev # Elevation. glaciers # Glacier locations storms # Storm tracks data ``` ```{r} p <- storms |> ggplot(aes(y = wind, x = pressure, color = type)) + geom_point(alpha = 0.3) p p + geom_smooth() ``` All storms Determine the part of the map to plot the storm paths on. Compute the minimum and maximum values of the latitude and longitude. ```{r} bbox <- storms |> select(lat, long) |> map_df(range) # using the purrr R package bbox ``` ```{r} base_map <- map_data("world") |> ggplot( aes(x = long, y = lat)) + geom_path(aes(group = group), color = "black", size = 0.1) + lims(x = bbox$long, y = bbox$lat) base_map <- base_map + geom_path(data = storms, aes(color = name, alpha = 0.01, size = wind), arrow = arrow(length = unit(0.005, "inches"))) + facet_wrap(~year) base_map base_map + theme(legend.position = "none") ``` Show the legend. ```{r} legend <- cowplot::get_legend(base_map) cowplot::plot_grid(legend, scale = .5) ``` Only Tropical Storms ```{r} base_map <- map_data("world") |> ggplot(aes(x = long, y = lat)) + geom_path(aes(group = group), color = "black", size = 0.1) + lims(x = bbox$long, y = bbox$lat) base_map storms2 <- storms |> filter(type == "Tropical Storm") base_map + geom_path(data = storms2, aes(color = name, alpha = 0.01, size = wind), arrow = arrow(length = unit(0.005, "inches"))) + facet_wrap(~year) + theme(legend.position = "none") ``` Some futher maps ```{r} library(maps) state <- map_data("state") county <- map_data("county") usa <- map_data("usa") world <- map_data("world") ``` states ```{r} state ``` ```{r} gg <- ggplot() gg <- gg + geom_map(data=state, map=state, aes(long, lat, map_id=region), color="#2b2b2b", fill=NA, size=0.15) gg ``` ```{r} gg <- ggplot() gg <- gg + geom_map(data=county, map=county, aes(long, lat, map_id=region), color="#2b2b2b", fill=NA, size=0.15) gg gg <- ggplot() gg <- gg + geom_map(data=state, map=state, aes(long, lat, map_id=region), color="#2b2b2b", fill=NA, size=0.15) gg gg <- ggplot() gg <- gg + geom_map(data=usa, map=usa, aes(long, lat, map_id=region), color="#2b2b2b", fill=NA, size=0.15) gg ``` ```{r} ggplot() + borders("county", c("washington", "california","texas")) ```