thomasp85 / ggfx

Filters and Shaders for 'ggplot2'
https://ggfx.data-imaginist.com
Other
166 stars 4 forks source link

geom_line() - Error in validDetails.polyline(x): invalid 'arrow' argument #4

Closed jbaileyh closed 3 years ago

jbaileyh commented 4 years ago

Thanks for working on this - it's a great idea. I suspect i'm doing something wrong and I know this is in early stages so wouldn't expect everything to work but wanted to flag - just incase it might be useful. I have tried a few different geoms with the example plot in the documentation but it didn't seem to like geom_line (others worked ok).

library(ggplot2)
library(ggfx)

ggplot(mtcars, aes(mpg, disp)) + 
    with_shadow(geom_line(colour = 'red', size = 3), sigma = 3) +
    geom_line()
#> Error in validDetails.polyline(x): invalid 'arrow' argument

It may have something to do with this in {grid} (though it may not):

######################################
# POLYLINES primitive
######################################
# Very similar to LINES primitive, but allows
# multiple polylines via 'id' and 'id.lengths' args
# as per POLYGON primitive
validDetails.polyline <- function(x) {
  if (!is.unit(x$x) ||
      !is.unit(x$y))
      stop("'x' and 'y' must be units")
  if (!is.null(x$id) && !is.null(x$id.lengths))
      stop("it is invalid to specify both 'id' and 'id.lengths'")
  if (length(x$x) != length(x$y))
      stop("'x' and 'y' must be same length")
  if (!is.null(x$id) && (length(x$id) != length(x$x)))
      stop("'x' and 'y' and 'id' must all be same length")
  if (!is.null(x$id))
      x$id <- as.integer(x$id)
  if (!is.null(x$id.lengths) && (sum(x$id.lengths) != length(x$x)))
      stop("'x' and 'y' and 'id.lengths' must specify same overall length")
  if (!is.null(x$id.lengths))
      x$id.lengths <- as.integer(x$id.lengths)
  if (!(is.null(x$arrow) || inherits(x$arrow, "arrow")))
      stop("invalid 'arrow' argument")
  x
}