teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
534 stars 32 forks source link

`geom_pointpath()` crashes with repeated points #73

Closed MCMaurer closed 1 year ago

MCMaurer commented 1 year ago

geom_pointpath() errors if there are repeated points in the path.

Here is a minimal example:

library(tidyverse)
library(ggh4x)

tibble(x = 1:5, y = 1:5) %>% 
  ggplot(aes(x,y)) +
  geom_pointpath()

tibble(x = c(1:5,5), y = c(1:5,5)) %>% 
  ggplot(aes(x,y)) +
  geom_pointpath()

The second option crashes because the coordinate 5,5 is repeated.

Here is the trace for the error:

Error in `grid.Call.graphics()`:
! invalid line type
Backtrace:
     ▆
  1. ├─base (local) `<fn>`(x)
  2. ├─ggplot2:::print.ggplot(x)
  3. │ ├─grid::grid.draw(gtable)
  4. │ └─grid:::grid.draw.gTree(gtable)
  5. │   └─grDevices::recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
  6. ├─grid:::drawGTree(x)
  7. │ ├─grid::grid.draw(x$children[[i]], recording = FALSE)
  8. │ └─grid:::grid.draw.gTree(x$children[[i]], recording = FALSE)
  9. │   └─grDevices::recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
 10. ├─grid:::drawGTree(x)
 11. │ ├─grid::grid.draw(x$children[[i]], recording = FALSE)
 12. │ └─grid:::grid.draw.gTree(x$children[[i]], recording = FALSE)
 13. │   └─grDevices::recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
 14. ├─grid:::drawGTree(x)
 15. │ ├─grid::grid.draw(x$children[[i]], recording = FALSE)
 16. │ └─grid:::grid.draw.grob(x$children[[i]], recording = FALSE)
 17. │   └─grDevices::recordGraphics(drawGrob(x), list(x = x), getNamespace("grid"))
 18. └─grid:::drawGrob(x)
 19.   ├─grid::drawDetails(x, recording = FALSE)
 20.   └─grid:::drawDetails.segments(x, recording = FALSE)
 21.     └─grid:::grid.Call.graphics(...)
teunbrand commented 1 year ago

Thanks for finding this bug! I can reproduce it on my end, and should be relatively straightforward to fix.

MCMaurer commented 1 year ago

Wonderful, glad to hear it! As an aside, I've been using a ton of stuff from the package and just want to say how absolutely fantastic it is!