hughjonesd / ggmagnify

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

Fails with non-continuous scales #8

Open hughjonesd opened 1 year ago

hughjonesd commented 1 year ago

Test case which works fine without the call to scale:

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + 
  scale_y_binned(n.breaks = 5) + 
  geom_magnify(x = 15, width = 5, y = 200, height = 100, to_x = 30, to_y = 200, magnify = c(1, 1.5))
hughjonesd commented 1 year ago

The underlying reason is https://github.com/tidyverse/ggplot2/issues/5294: xmin and xmax get trashed by scale_x_binned and friends.

hughjonesd commented 1 year ago

geom_magnify2 is a workaround

hughjonesd commented 1 year ago

Updated version where this still breaks:

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + 
  scale_y_binned(n.breaks = 5) + 
  geom_magnify_tile(x = 15, width = 5, y = 200, height = 100, to_x = 30, to_y = 200, to_width = 5, to_height = 150)

or

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + 
  scale_y_binned(n.breaks = 5) + geom_magnify(from = c(12.5, 150, 17.5, 250) , to = c(27.5,125, 32.5, 275))