davidsjoberg/ggsankey

"sum_" function missing for geom_sankey_bump()

engineerchange opened this issue · 2 comments

Following the sum_ issue reported in #1, I have the same issue with the example provided in the readme.

I tried:

library(ggsankey)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(gapminder)

df <- gapminder %>%
    group_by(continent, year) %>%
    summarise(gdp = (sum_(pop * gdpPercap)/1e9) %>% round(0), .groups = "keep") %>%
    ungroup()
#> Error: Problem with `summarise()` input `gdp`.
#> x could not find function "sum_"
#> ℹ Input `gdp` is `(sum_(pop * gdpPercap)/1e+09) %>% round(0)`.
#> ℹ The error occurred in group 1: continent = "Africa", year = 1952.

ggplot(df, aes(x = year,
               node = continent,
               fill = continent,
               value = gdp)) +
    geom_sankey_bump(space = 0, type = "alluvial", color = "transparent", smooth = 6) +
    scale_fill_viridis_d(option = "A", alpha = .8) +
    theme_sankey_bump(base_size = 16) +
    labs(x = NULL,
         y = "GDP ($ bn)",
         fill = NULL,
         color = NULL) +
    theme(legend.position = "bottom") +
    labs(title = "GDP development per continent")
#> Error:   You're passing a function as global data.
#>   Have you misspelled the `data` argument in `ggplot()`

Created on 2021-04-03 by the reprex package (v1.0.0)

I also tried removing sum_ and replacing with sum when writing to the variable df, but I also had no luck.

See here:

df <- gapminder %>%
  group_by(continent, year) %>%
  summarise(gdp = (sum(pop * gdpPercap)/1e9) %>% round(0), .groups = "keep") %>%
  ungroup()

ggplot(df, aes(x = year,
               node = continent,
               fill = continent,
               value = gdp)) +
  geom_sankey_bump(space = 0, type = "alluvial", color = "transparent", smooth = 6) +
  scale_fill_viridis_d(option = "A", alpha = .8) +
  theme_sankey_bump(base_size = 16) +
  labs(x = NULL,
       y = "GDP ($ bn)",
       fill = NULL,
       color = NULL) +
  theme(legend.position = "bottom") +
  labs(title = "GDP development per continent")

My console error is different than reprex's for some reason; this is my console error:

Error: Problem with `summarise()` input `flow_freq`.
x could not find function "sum_"
ℹ Input `flow_freq` is `sum_(value)`.
ℹ The error occurred in group 1: n_x = 1952, node = "Oceania 1952", n_next_x = 1957, next_node = "Oceania 1957".
chalg commented

Was about the raise the same issue.

Thanks! It was problem with my use of my own sum_ function from hablar ;) Now I've removed that dependency and it should work fine!