'ggsankey: Error: `n()` must only be used inside dplyr verbs

I'm new using ggsankey.

I have the following data

t1 <- sample(x = c("Hosp A", "Hosp B", "Hosp C","Hosp D") , size = 100, replace=TRUE)
t2 <- sample(x = c("Male", "Female")   , size = 100, replace=TRUE)'''
d <- data.frame(cbind(t1,t2))
names(d) <- c('Hospital', 'Gender')
head(d)
 Hospital Gender
1   Hosp D   Male
2   Hosp D Female
3   Hosp D Female
4   Hosp A Female
5   Hosp A Female
6   Hosp B   Male

Then I used the make_long function

df <- d %>%
make_long(Hospital, Gender)

pl <- ggplot(df, aes(x = x
                 , next_x = next_x
                 , node = node
                 , next_node = next_node
                 , fill = factor(node)
                 , label = node))
pl +geom_sankey(flow.alpha = 0.5
            , node.color = "black"
            ,show.legend = FALSE)

This last part shows me the error:

"Error: n() must only be used inside dplyr verbs."

Could someone please help me!



Solution 1:[1]

It could be because you have already loaded the plyr (or Hmisc) package. I think that once you detach these packages, your problem should be solved. See this link! for more specifics on this issue. Hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2733968