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

Feature request: Make usable with facets #14

Open
BAndrews22 opened this issue Jun 14, 2024 · 4 comments
Open

Feature request: Make usable with facets #14

BAndrews22 opened this issue Jun 14, 2024 · 4 comments
Labels
reprex Reproducible example required

Comments

@BAndrews22
Copy link

Currently, when trying to plot multiple Sankeys at once with facet_grid(), the connectors are much too thin and do not take up the entire space of the node.

@pepijn-devries
Copy link
Owner

pepijn-devries commented Jun 14, 2024

Hi @BAndrews22,

I'm not sure if this is a bug report, a feature request or even an issue. It sounds as if you are trying something that is either not feasible or possible. In order to help you or to prepare a fix (if needed) I need a more detailed report with a reprex. I'm looking forward to your report.

Cheers,

Pepijn

@pepijn-devries pepijn-devries added the reprex Reproducible example required label Jun 14, 2024
@BAndrews22
Copy link
Author

Hi Pepijn,
Thanks a mil for solving my other issue with printing to PDF.
I can confirm that this issue is related, the area of the facets gets too narrow.
By resizing the plot area, also the facetted plot works. But one really has to fiddle with the width and height to get it work.

I have done the same plot with the ggsankey package and it seems much less sensitive to the aspect ratio.
However, the output of your package looks better and its syntax is cleaner, so I will rather adjust the aspect ratio.

Just for completeness, below a repex. Depending on the size of the plot window, the output looks correct or not.
Many thanks!

library(ggplot2)
library(ggsankeyfier)
theme_set(theme_light())
data("ecosystem_services")

es_sub <-
  ecosystem_services |>
  subset(RCSES > quantile(RCSES, 0.99)) |>
  pivot_stages_longer(c("activity_realm", "biotic_realm", "service_section"), "RCSES", "service_section")

es2 <- cbind(es_sub, pl=rep(1:10, each=nrow(es_sub)))
pos <- position_sankey(v_space = "auto", order = "ascending")

ggplot(es2, aes(x = stage, y = RCSES, group = node, connector = connector, edge_id = edge_id)) + 
  geom_sankeyedge(aes(fill = service_section), position = pos) +   
  geom_sankeynode(position = pos) + 
  facet_wrap(~pl, nrow=2)

@pepijn-devries
Copy link
Owner

This is a trade-off of how the plotting routine for the edges is implemented. I'm not sure if this can be fixed. If I do succeed, I will report back here...

@BAndrews22
Copy link
Author

That's great. Thanks a mil!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex Reproducible example required
Projects
None yet
Development

No branches or pull requests

2 participants