No plot shown if data is in layers
hughjonesd opened this issue · comments
Example:
dfr <- data.frame(x = runif(100), y = runif(100))
# works
ggplot(dfr, aes(x, y)) +
geom_point() +
geom_magnify(from = c(.25, .35, .25, .35), to = c(0.2, .6, 0.5, .8))
# no magnify
ggplot() +
geom_point(data = dfr, mapping = aes(x,y)) +
geom_magnify(from = c(.25, .35, .25, .35), to = c(0.2, .6, 0.5, .8))
There's no warning either.
I seem to meet the same problem when trying to enlarge an area of a map using sf package:
# no magnify and warning either
ocean_map <- rnaturalearth::ne_coastline(scale = 'large', returnclass = c("sf"))
p <- ggplot() +
geom_sf(data = ocean_map, aes(geometry = geometry)) +
theme_bw() +
geom_magnify(from = c(-20, 30, 37, 60), to = c(40, 120, 27, 70), shape = "outline")
p
Fixing this will add a lot of complexity, I think. A workaround is simply to add your data to the geom_magnify()
call:
ggplot() +
geom_point(data = blah, ...) +
geom_magnify(data = blah, from = ..., to = ...)
It solved my problem perfectly. Thank you!