Description Usage Arguments Examples
Scale regions in a map
1 |
map |
map object as generated by functions such as 'process_shape', 'ggplot2::map_data', or 'ggplot2::fortify' |
condition |
logical expression describing the subset of the map to use for the scaling |
scale |
numeric vector of length 2 used to scale the map region in longitude and latitude. Scale factors should be positive (negative values flip region). |
set_to |
numeric vector of length 2. Set center of the region (defined by range in lat and long) to this longitude and latitude |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | states <- states %>% group_by(group) %>% mutate(bbox = diff(range(long))*diff(range(lat)))
states <- states %>% filter(bbox > 0.15)
states %>% ggplot(aes(x = long, y = lat)) + geom_path(aes(group = group))
inset <- shift(states, "NAME", "Hawaii", shift_by = c(51, 5.5))
inset <- scale(inset, NAME=="Alaska", scale=0.3, set_to=c(-120, 27))
inset %>% ggplot(aes(long, lat)) + geom_path(aes(group=group))
inset <- inset %>%
filter(lat > 20)
inset %>%
ggplot(aes(long, lat)) + geom_path(aes(group=group))
# Iowa in a Manhattan block design
counties %>% filter(STATE == "Iowa") %>%
tidyr::nest(-group) %>%
mutate( data = data %>%
purrr::map(.f = function(x) scale(x, scale=0.8))) %>%
tidyr::unnest(data) %>%
ggplot(aes(x = long, y = lat, group = group)) + geom_polygon()
# North Carolina becomes more giraffe-like this way.
counties %>% filter(STATE == "North Carolina") %>%
tidyr::nest(-group) %>%
mutate( data = data %>%
purrr::map(.f = function(x) scale(x, scale=0.9))) %>%
tidyr::unnest(data) %>%
ggplot(aes(x = long, y = lat, group = group)) + geom_polygon()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.