hughjonesd / ggmagnify

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

Surprising failure with xlim #14

Open hughjonesd opened 1 year ago

hughjonesd commented 1 year ago

Example:

library(ggplot2)
ggp <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species, shape = Species))
ggp2 <- ggp + geom_point()

from <- c(2.5, 3.0, 5.5, 6.0)
to <- c(3.5, 4.5, 4.5, 5.5)
ggp2 + xlim(2,5) + geom_magnify(aes(from = Species=="versicolor" & Sepal.Length < 6), to = c(4, 4.8, 5, 6))

This doesn't print a magnified inset, and gives a warning about dropped cases.

The failure is because xmin becomes NA in the data, which then leads all cases to be dropped as incomplete.

Not sure why xmin is becoming NA. It's fine with xlim(1.9, 5) ; or with expand = 0.

hughjonesd commented 1 year ago

StatMagnify unsurprisingly sets xmin to 1.94. Then some time before the geom, that 1.94 becomes NA in the data.