Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping by variable in geom_link2 throws error #328

Open
jlambvo opened this issue Dec 26, 2024 · 0 comments
Open

Grouping by variable in geom_link2 throws error #328

jlambvo opened this issue Dec 26, 2024 · 0 comments

Comments

@jlambvo
Copy link

jlambvo commented Dec 26, 2024

With ggplot2::geom_path, setting group = _y_ in the aesthetic mapping connects observations with the same value for y. For example, I am visualizing the paths taken by agents in a 2D environment, where I want to stratify paths by a unique agent ID. However, when I try to to use this argument in geom_link2 I receive the error:

Warning message:
Computation failed in `stat_link2()`.
Caused by error in `data.frame()`:
! arguments imply differing number of rows: 2, 0

A minimal working example using the reference:

lines <- data.frame(
  x = c(5, 12, 15, 9, 6),
  y = c(17, 20, 4, 15, 5),
  xend = c(19, 17, 2, 9, 5),
  yend = c(10, 18, 7, 12, 1),
  width = c(1, 10, 6, 2, 3),
  group = c("a", "a", "b", "b", "c")

 ggplot(lines) +
     geom_link2(aes(x = x, y = y, colour = colour, size = width, group = group),
                lineend = 'round', n = 500)
)

In fact, this works when setting group to any of the columns. It seems to work only if there are at least 2 observation in each group and the same number of observations across groups (2 <= N_i == N_(-i)).

Is this expected, and is there a way to achieve groups as in geom_path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant