library(pacman)
p_load(tidyverse, nasaweather)
atmos # Atmospheric data.
borders <- ungroup(borders) # Country borders
elev # Elevation.
glaciers # Glacier locations
storms # Storm tracks data
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.
bbox <- storms %>%
select(lat, long) %>%
map_df(range) # using the purrr R package
bbox
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)
storms <- storms %>%
unite("the_date", c(year, month, day), sep="-", remove="FALSE") %>%
mutate(the_date = lubridate::ymd(the_date))
base_map + geom_path(data = storms, aes(color = name, alpha = 0.01, size = wind),
arrow = arrow(length = unit(0.005, "inches"))) +
facet_wrap(~year) +
theme(legend.position = "none")
Only Tropical Storms
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
library(maps)
state <- map_data("state")
county <- map_data("county")
usa <- map_data("usa")
world <- map_data("world")
states
state
gg <- ggplot()
gg <- gg + geom_map(data=state, map=state,
aes(long, lat, map_id=region),
color="#2b2b2b", fill=NA, size=0.15)
Ignoring unknown aesthetics: x, y
gg
gg <- ggplot()
gg <- gg + geom_map(data=county, map=county,
aes(long, lat, map_id=region),
color="#2b2b2b", fill=NA, size=0.15)
Ignoring unknown aesthetics: x, y
gg
gg <- ggplot()
gg <- gg + geom_map(data=state, map=state,
aes(long, lat, map_id=region),
color="#2b2b2b", fill=NA, size=0.15)
Ignoring unknown aesthetics: x, y
gg
gg <- ggplot()
gg <- gg + geom_map(data=usa, map=usa,
aes(long, lat, map_id=region),
color="#2b2b2b", fill=NA, size=0.15)
Ignoring unknown aesthetics: x, y
gg
ggplot() + borders("county", c("washington", "california","texas"))
LS0tCnRpdGxlOiAiTWFwcyIKb3V0cHV0OgogIHdvcmRfZG9jdW1lbnQ6IGRlZmF1bHQKICBodG1sX25vdGVib29rOiBkZWZhdWx0CiAgcGRmX2RvY3VtZW50OiBkZWZhdWx0Ci0tLQoKCmBgYHtyfQpsaWJyYXJ5KHBhY21hbikKCnBfbG9hZCh0aWR5dmVyc2UsIG5hc2F3ZWF0aGVyKQoKYXRtb3MJICAgICAgICAgICAgICAgICAgICAgICAjIEF0bW9zcGhlcmljIGRhdGEuCmJvcmRlcnMgPC0gdW5ncm91cChib3JkZXJzKQkgIyBDb3VudHJ5IGJvcmRlcnMsIHVuZ3JvdXAgZml4ZXMgYSBwcm9ibGVtIHdpdGgga25pdHRpbmcuCmVsZXYJICAgICAgICAgICAgICAgICAgICAgICAjIEVsZXZhdGlvbi4KZ2xhY2llcnMgICAgICAgICAgICAgICAgICAgICAjIEdsYWNpZXIgbG9jYXRpb25zCnN0b3JtcwkgICAgICAgICAgICAgICAgICAgICAjIFN0b3JtIHRyYWNrcyBkYXRhCgpgYGAKCgpgYGB7cn0KcCA8LSBzdG9ybXMgJT4lIGdncGxvdChhZXMoeSA9IHdpbmQsIHggPSBwcmVzc3VyZSwgY29sb3IgPSB0eXBlKSkgKwogIGdlb21fcG9pbnQoYWxwaGEgPSAwLjMpIAoKcAoKcCArIGdlb21fc21vb3RoKCkKYGBgCgoKQWxsIHN0b3JtcwoKRGV0ZXJtaW5lIHRoZSBwYXJ0IG9mIHRoZSBtYXAgdG8gcGxvdCB0aGUgc3Rvcm0gcGF0aHMgb24uICBDb21wdXRlIHRoZSBtaW5pbXVtIGFuZCBtYXhpbXVtIHZhbHVlcyBvZiB0aGUgbGF0aXR1ZGUgYW5kIGxvbmdpdHVkZS4KCmBgYHtyfQpiYm94IDwtIHN0b3JtcyA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