Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facet_zoom with mapping #57

Open
jonocarroll opened this issue Feb 9, 2017 · 2 comments
Open

facet_zoom with mapping #57

jonocarroll opened this issue Feb 9, 2017 · 2 comments
Labels
feature a feature request or enhancement

Comments

@jonocarroll
Copy link

Similar but different to #56. With geom_sf() on its way to ggplot2 it would be great to have projection-aware facet_zooming. Part of this would likely require that the original and zoomed panels not necessarily be the same height/width, in order to maintain projections. For example, it would be great to be able to zoom a region of a map

library(dplyr)
library(maps)
library(ggplot2) 
library(ggforce) 
aus_map <- map_data("world") %>% 
  filter(region == "Australia", 
         is.na(subregion) | subregion %in% c("Tasmania", "Kangaroo Island"))
p <- ggplot() + 
  geom_polygon(aes(x = long, y = lat, group = group), 
               colour = NA, 
               data = aus_map) 
p + facet_zoom(xlim = c(131, 148), ylim = c(-45, -32), 
               zoom.size = 4)

Attempting to do similar with the sf branch of ggplot2 just produces the unzoomed map in both panels and seems to miss the zoom highlight, though it certainly looks neater.

library(sf)      
library(maps)
library(ggplot2) # devtools::install_github("tidyverse/ggplot2@sf") ## NOTE sf branch
library(ggforce)
world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE))
ggplot() + 
  geom_sf(data = world1) + 
  coord_sf(xlim = c(110, 160), ylim = c(-45, -10)) + 
  facet_zoom(xlim = c(132, 148), ylim = c(-45, -32))

This has potential to look really awesome if the unzoomed panel could have its height adjusted to maintain projection (width can currently be somewhat manually adjusted via zoom.size) and if the subsetting was compatible with the sf features (appropriate highlight/zoom).

I know it's a dev feature, so this is just 'down the track' thinking.

@thomasp85 thomasp85 added the feature a feature request or enhancement label Apr 27, 2017
@johnmutiso
Copy link

johnmutiso commented Oct 30, 2019

You won't be able to specify axis limits twice..., therefore, the xlim and ylim in the coord_sf function affects the functionality of facet_zoom

@jonocarroll
Copy link
Author

I haven't looked at this for a while, but that makes sense - is there a better way to do the zoom, or does this need something like inherit.aes = FALSE?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants