hughjonesd / ggmagnify

Create a magnified inset of part of a ggplot object

Home Page:https://hughjonesd.github.io/ggmagnify/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Surprising failure with xlim

hughjonesd opened this issue · comments

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.

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