You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to merge two sankey plots (mariculture and capture) with the same nodes (oceans) and the same next-node (country's income level), but different flow values (mariculture amount and captured amount). I was planning to use one sankey plot to show the two flow values at one time, the total values at nodes and next-nodes can be respectively added up. But it seems to be unable to do so? hence the question, is it true that one node can connect with one next-node by only one flow? In my case, I want to connect them with two flows.
library(ggplot2)
library(ggsankey)
library(dplyr)
#prepare the mariculture data, node is ocean, next_node is income level, value is seafood amount
dfa<-dfaqua.incomelevel %>%
select (node , next_node , value)%>%
make_long(node, next_node, value = value) %>%
mutate(type = 'Mariculture')
dfa<- data.frame(dfa)
#prepare the capture data, node is ocean, next_node is income level, value is seafood amount
dfc<-dfcatch.incomelevel %>%
select (node , next_node , value)%>%
make_long(node, next_node, value = value) %>%
mutate(type = 'Capture')
dfc<- data.frame(dfc)
#combine the two make_long data, data are provided here https://filetransfer.io/data-package/5wKjjvvU#link
dfinput <- rbind(dfa, dfc)
dfinput <-dfinput%>%
group_by(x, node) %>%
mutate(total = sum(value))
#make the merged sankey plot, but the output is weird, not what I want
g <- ggplot (dfinput
, aes(x = x
, next_x = next_x
, node = node
, next_node = next_node
, fill = factor(type) #only colour the flow by type: mariculture and capture
, value = value #flow value
, label = paste0(node, " (", round(total,0), ")")
))+
geom_sankey(flow.alpha = 0.5, node.color = 1) +
geom_sankey_label(size = 3.5, color = 1, fill = "white") +
scale_fill_viridis_d() +
theme_sankey(base_size = 16)+
guides(fill = guide_legend(title = "Income Level"))
print(g)
The text was updated successfully, but these errors were encountered:
I wanted to merge two sankey plots (mariculture and capture) with the same nodes (oceans) and the same next-node (country's income level), but different flow values (mariculture amount and captured amount). I was planning to use one sankey plot to show the two flow values at one time, the total values at nodes and next-nodes can be respectively added up. But it seems to be unable to do so? hence the question, is it true that one node can connect with one next-node by only one flow? In my case, I want to connect them with two flows.
The text was updated successfully, but these errors were encountered: