tidyverse / tidyverse/ggplot2

`geom_rug()` gives an unhelpful error w/ `coord_radial()`

Open
#6,794 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

coord :world_map: layers :chart_with_upwards_trend:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproducible example with geom_rug() and coord_radial(), then compare it with the coord_cartesian() version. Trace the geom-to-grob conversion to determine whether the combination should be rejected clearly or handled differently; done means the radial example no longer produces an unhelpful error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.