-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Now that the "Persistence-Refactor" branch has StatPersistence inheriting from Stat instead of StatIdentity, rows of data where death == Inf are being removed in $compute_layer(). Specifically, this is happening because Stat$compute_layer() removes rows where required aesthetics are infinite, as you can see in its source (lines 203 - 207):
data <- remove_missing(data, params$na.rm, c(required_aes, self$non_missing_aes), snake_class(self), finite = TRUE )
I've implemented a fix in dc68533, I added a few lines at the end of StatPersistence$setup_data() where I derive a new computed variable (infinite_death) and temporarily set infinite death values to 0(lines 309 - 314):
data$infinite_death <- is.infinite(data$death) data$death[data$infinite_death] <- 0
Then, in StatPersistence$compute_group() I reverse this, resetting the values of death to Inf where appropriate, per data$infinite_death (lines 335 - 337).
data$death[data$infinite_death] <- Inf
This approach seems to work very well, infinite values are being plotted as intended across the board. And, as a bonus, infinite_death is now available as a computed variable and can be mapped to in aes().
I think this also presents an interesting opportunity -- I've seen persistence diagrams where infinity is represented as a dashed line at some arbitrary point on the y-axis; it would be very easy to implement an argument that would allow users to plot infinity at a given y value (e.g. if all finite death values are below 1.5, one could select 1.5 as the visual definition of infinity, accompanied with geom_hline(yintercept = 1.5, linetype = "dashed"). This would give an alternative method of visualizing points at infinity in geom_peristence() in case users object to the "half" points at the top-edge of the y-axis. (This also works well with the new infinite_death computed variables, allowing further visual emphasis that the points at y = 1.5 are distinct)