Scale regions in a map

scale(map, condition = NULL, scale = 1, set_to = NULL)

Arguments

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

Examples

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))
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Error in delta_x - mean(range(submap$long)) + set_to[1]: non-numeric argument to binary operator
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()