hughjonesd / ggmagnify

Create a magnified inset of part of a ggplot object
https://hughjonesd.github.io/ggmagnify/
Other
275 stars 3 forks source link

Screws up when multiple polygons are magnified #13

Closed hughjonesd closed 1 year ago

hughjonesd commented 1 year ago

For a map:

library(ggplot2)
library(ggmagnify)
usa <- sf::st_as_sf(maps::map("state", fill=TRUE, plot =FALSE))

ggpm <- ggplot(usa) + geom_sf() +
         coord_sf(default_crs = sf::st_crs(4326), ylim = c(10, 50)) 

ggpm + geom_magnify(aes(from = ID %in% c("texas", "arizona")),
                    to = c(-125, -98, 10, 30), 
                    shape = "outline", 
                    aspect = "fixed", 
                    expand = 0) 

image

hughjonesd commented 1 year ago

This could be fixed better by doing each polygon separately; but there'd probably need to be an option for that!