Skip to content

geom_spoke uses the wrong angle if radius is Inf in some cases #6671

@eliocamp

Description

@eliocamp

Simple segment at a 45° angle:

library(ggplot2)

ggplot() +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = 10),
    aes(0, 0, angle = angle, radius = radius),
  )  +
  annotate("point", x = 2, y = 2)

The angle is correct (passes through the x = y point)

I can use radius = Inf to extend it to the limits of the plots and still works.

ggplot() +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = Inf),
    aes(0, 0, angle = angle, radius = radius),
  )  +
  annotate("point", x = 2, y = 2)

However, when there is other data, infinite radius is draw with the wrong angle

data.frame(x = rnorm(100, sd = 2)) |> 
  transform(y = x^2 + rnorm(100)) |> 
  ggplot(aes(x, y)) +
  geom_point() +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = Inf),
    aes(0, 0, angle = angle, radius = radius),
  ) +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = 10),
    color = "red",
    aes(0, 0, angle = angle, radius = radius),
  )  +
  annotate("point", x = 10, y = 10, color = "red")

It seems to be pointing to the upper right corner of the plot

data.frame(x = rnorm(100, sd = 2)) |> 
  transform(y = x^2 + rnorm(100)) |> 
  ggplot(aes(x, y)) +
  geom_point() +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = Inf),
    aes(0, 0, angle = angle, radius = radius),
  ) +
  geom_spoke(
    data = data.frame(angle = pi / 4, radius = 10),
    color = "red",
    aes(0, 0, angle = angle, radius = radius),
  )  +
  annotate("point", x = 10, y = 10, color = "red") +
  lims(y = c(NA, 30))

Metadata

Metadata

Assignees

No one assigned

    Labels

    layers 📈messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions