Query regarding faceting
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.
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.
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
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)

Thanks I can confirm it works at my end too.
As I see it, this could be closed as it was about data preparation before using ggsankey. Is that correct?
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: @.***>