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

Code Gives this Error #16

Open
benjaminwnelson opened this issue May 6, 2021 · 6 comments
Open

Code Gives this Error #16

benjaminwnelson opened this issue May 6, 2021 · 6 comments

Comments

@benjaminwnelson
Copy link

Any idea why it's giving this error?

Error in data.frame(x = full_values$x, y = yy[, iStream * 2], group = as.integer(.group)) :
arguments imply differing number of rows: 1000, 1126, 1

@davidsjoberg
Copy link
Owner

I had someone else have the same error but I don't have a reproducible example. Do you have one?

@benjaminwnelson
Copy link
Author

Unfortunately, I don't. I'll look into it more

@noahtolsen
Copy link

I think I've figured out what the issue is here. When the grouping variable is numeric, I tend to get this error. But if I convert it to a character it seems to fix things. Reproducible example of failing and working code below!

Broken because of numeric grouping variable:

library(ggstream)
library(ggplot2)
library(dplyr)

blockbusters %>% 
  mutate(genre2 = if_else(genre == 'Action', 1,
                          if_else(genre == 'Adventure', 2,
                                  if_else(genre == 'Animation', 3,
                                          if_else(genre == 'Comedy', 4,
                                                  if_else(genre == 'Drama', 5, 6)))))) %>% 
ggplot(aes(year, box_office, fill = genre2)) +
  geom_stream()

Working because grouping variable is a character:

library(ggstream)

ggplot(blockbusters, aes(year, box_office, fill = genre)) +
  geom_stream()

@wurli
Copy link

wurli commented Jul 20, 2021

I'm getting this error and it seems to be because n_grid has to be at least 2% more than the number of observations per group. Here's a reprex:

set.seed(123)

library(ggplot2)
library(ggstream)

test_bug <- function(n_observations, n_grid) {
  
  data.frame(
    x = rep(1:n_observations, 4),
    y = rnorm(4 * n_observations),
    fill = rep(letters[1:4], each = n_observations)
  ) %>% 
    ggplot(aes(x = x, y = y, fill = fill)) + 
    geom_stream(n_grid = n_grid)
  
}

# Fails
test_bug(n_observations = 100, n_grid = 101)
# Works
test_bug(n_observations = 100, n_grid = 102)

# Fails
test_bug(n_observations = 1000, n_grid = 1019)
# Works
test_bug(n_observations = 1000, n_grid = 1020)

@AntonioAlegriaH
Copy link

I'm getting this error and it seems to be because n_grid has to be at least 2% more than the number of observations per group. Here's a reprex:

set.seed(123)

library(ggplot2)
library(ggstream)

test_bug <- function(n_observations, n_grid) {
  
  data.frame(
    x = rep(1:n_observations, 4),
    y = rnorm(4 * n_observations),
    fill = rep(letters[1:4], each = n_observations)
  ) %>% 
    ggplot(aes(x = x, y = y, fill = fill)) + 
    geom_stream(n_grid = n_grid)
  
}

# Fails
test_bug(n_observations = 100, n_grid = 101)
# Works
test_bug(n_observations = 100, n_grid = 102)

# Fails
test_bug(n_observations = 1000, n_grid = 1019)
# Works
test_bug(n_observations = 1000, n_grid = 1020)

This worked for me. But also being especific with the exact number of observations inside n_grid()

@7yl4r
Copy link

7yl4r commented Dec 12, 2024

So the workaround is:

ggplot(
  [...]
  n_grid = length(df[[1]])*1.2
)

Worked for me. Thanks!

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

6 participants