Skip to content

geom_rug() gives an unhelpful error w/ coord_radial() #6794

@jack-davison

Description

@jack-davison
data.frame(x = seq(0, 360, 20), y = 1:19) |>
  ggplot2::ggplot() +
  ggplot2::geom_point(
    ggplot2::aes(x = x, y = y)
  ) +
  ggplot2::coord_radial() +
  ggplot2::geom_rug(
    ggplot2::aes(y = NULL, x = x)
  )
Error in `ggplot2::geom_rug()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 2nd layer.
Caused by error in `$<-.data.frame`:
! replacement has 0 rows, data has 19
Run `rlang::last_trace()` to see where the error occurred.

It might make sense for geom_rug() not to work with coord_radial(), but this isn't a helpful error message for a user.

For clarity, I only encountered this when writing a package function that can optionally return a radial plot - I wasn't really after putting a rug on a polar plot. But it was a strange error to debug!

The same code works fine with coord_cartesian().

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions