Created
September 28, 2023 00:22
-
-
Save elipousson/a95d036d54082828db1d99cd66e91ceb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(sf) | |
| library(dplyr) | |
| # Can you convert `storms_sf` to make the feature geometry represent | |
| # storm tracks instead of storm observations? | |
| storms_sf <- storms |> | |
| st_as_sf( | |
| coords = c("long", "lat"), | |
| crs = 4326 | |
| ) | |
| storms_sf <- storms_sf |> | |
| st_transform(crs = 4269) | |
| storm_tracks <- storms_sf |> | |
| arrange(year, month, day, hour) |> | |
| group_by(year, name) |> | |
| summarise( | |
| avg_wind = mean(wind), | |
| geometry = st_cast(st_union(geometry), to = "LINESTRING") | |
| ) |> | |
| ungroup() | |
| md_storm_tracks <- st_filter(storm_tracks, maryland) | |
| storm_tracks <- smoothr::smooth(storm_tracks) | |
| md_bbox <- st_bbox(maryland) | |
| md_storm_map <- md_storm_tracks |> | |
| ggplot() + | |
| geom_sf(aes(color = avg_wind)) + | |
| geom_sf(data = lower48, fill = NA, color = "black") + | |
| coord_sf( | |
| xlim = c(md_bbox$xmin, md_bbox$xmax), | |
| ylim = c(md_bbox$ymin, md_bbox$ymax) | |
| ) + | |
| theme_void() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment