ggsankey icon indicating copy to clipboard operation
ggsankey copied to clipboard

Query regarding faceting

Open drsantam opened this issue 4 years ago • 6 comments

It would be nice if the plots could be faceted using facet grid or other ggplot faceting methods. Is there a way to currently facet plots ? I am currently using cowplot and patchwork to assemble multiple plots into a single plot.

drsantam avatar Sep 22 '21 01:09 drsantam

It doesnt work? Do you have an exemple?

Bästa hälsningar David

On 22 Sep 2021, at 03:59, Santam Chakraborty @.***> wrote:

 It would be nice if the plots could be faceted using facet grid or other ggplot faceting methods. Is there a way to currently facet plots ? I am currently using cowplot and patchwork to assemble multiple plots into groups.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

davidsjoberg avatar Sep 22 '21 05:09 davidsjoberg

Yes I am attaching an example dataset. In this dataset, each row corresponds to observations made on a single unit (say patient) and the arm represents the trial arm. When we use the make_long command, on this dataframe we have to select the columns called month_1, month_2 and month_3. The dataframe created by this command does not retain the arm and therefore I don't see a way to facet the plots by the arm. Please let me know if this is actually possible. example_data.csv

drsantam avatar Sep 22 '21 16:09 drsantam

I was curious how this might work. You can use group_modify() on a grouped dataframe to keep the grouping variable when using make_long(). Then faceting works as expected. Using your example data as df this code should do what you want?

df %>%
  group_by(arm) %>%
  group_modify(~make_long(.x,month_1:month_3)) %>%
  ggplot(aes(x = x, next_x = next_x, node = node, next_node = next_node, color = arm)) +
  geom_sankey() +
  geom_sankey_text(aes(label = node))+
  facet_grid(~arm)

image

jpaulitz avatar Sep 24 '21 08:09 jpaulitz

Thanks I can confirm it works at my end too.

drsantam avatar Mar 19 '22 14:03 drsantam

As I see it, this could be closed as it was about data preparation before using ggsankey. Is that correct?

stragu avatar Mar 30 '22 07:03 stragu

Yes. Thank you.

On Wed, 30 Mar 2022 at 13:24, Stéphane Guillou @.***> wrote:

As I see it, this could be closed as it was about data preparation before using ggsankey. Is that correct?

— Reply to this email directly, view it on GitHub https://github.com/davidsjoberg/ggsankey/issues/11#issuecomment-1082748353, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRPY4D7F5RZ3QAMBSJB6EDVCQCFBANCNFSM5EQFHV3Q . You are receiving this because you authored the thread.Message ID: @.***>

drsantam avatar Mar 30 '22 08:03 drsantam