grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
226 stars 7 forks source link

Custom legend not working with type = "density" plots #85

Closed grantmcdermott closed 6 months ago

grantmcdermott commented 10 months ago
library(plot2)

# fails silently
with(
  mtcars,
  plot2(
    x = mpg, by = cyl,
    type = "density", 
    legend = list(x = "bottom!")
  )
)


# fails outright
with(
  mtcars,
  plot2(
    x = mpg, by = cyl,
    type = "density", 
    legend = "bottom!"
  )
)
#> Error in if (names(fargs[["legend"]])[1] == "") names(fargs[["legend"]])[1] = "x": argument is of length zero

Interestingly, this isn't a problem if we feed it a density object directly.

# this works, though
with(
  mtcars,
  plot2(
    x = density(mpg), by = cyl,
    legend = "bottom!"
  )
)