davidsjoberg / ggsankey

Make sankey, alluvial and sankey bump plots in ggplot
Other
267 stars 32 forks source link

Define colour by the target node? (bug / feature request) #13

Open MPietzke opened 3 years ago

MPietzke commented 3 years ago

Thank's for the nice package! Is there a way to define the colour based on the target node, to illustrate where the flow goes to and not where it comes from?

# demodata 
df <- mtcars %>%
  make_long(cyl, vs, am, gear)

# with colour by node
ggplot(df, aes(x = x, 
               next_x = next_x, node = node, 
               next_node = next_node, 
               fill = factor(node), label = node)) +
  geom_sankey(flow.alpha = .6,
              node.color = "gray30") +
  geom_sankey_label(size = 3, color = "white", fill = "gray40") +
  scale_fill_viridis_d() +
  theme_sankey(base_size = 18) +
  labs(x = NULL) + 
  theme(legend.position = "none",
        plot.title = element_text(hjust = .5)) +
  ggtitle("Car features")

image

When using the examples and just replacing the fill = factor(node) with fill = factor(next_node) the structure breaks:

ggplot(df, aes(x = x, 
               next_x = next_x, node = node, 
               next_node = next_node, 
               fill = factor(next_node), label = node)) +
  geom_sankey(flow.alpha = .6,
              node.color = "gray30") +
  geom_sankey_label(size = 3, color = "white", fill = "gray40") +
  scale_fill_viridis_d() +
  theme_sankey(base_size = 18) +
  labs(x = NULL) + 
  theme(legend.position = "none",
        plot.title = element_text(hjust = .5)) +
  ggtitle("Car features")

image

Deusu commented 2 years ago

Hi! Did you have any luck solving this? I'm trying to do something very similar (coloring by an external value) and the structure breaks very similarly

symbiologist commented 1 year ago

I'm running into a similar issue and have tried a number of different ways to get around it, but haven't had any success. Would be really great to have this working

danilopatro commented 6 months ago

I'm facing the same problem. Unhappily, no news for now.

niacaruso commented 2 months ago

I'm also facing the same problem. Did anyone have any luck solving this?