Not enough flows in sankey plot

Good day everybody,

I have a problem with my sankey plot (see appendix).
I want to show a patient flow in whether or not criteria are met after starting a medication.
At the beginning (meets_criteria_0y) some patients already meet the criteria, others do not. This was determined again after 1 and 5 years.

The problem right now:
Some patients go from not complying on year 1 to complying on year 5. However, some of these were not meeting the criteria on baseline (start, marked it green in the picture of the appendix), while the other part was meeting the criteria on baseline (marked it pink in the picture of the appendix).
I want to visualize this (also for other thinkable options similair to this)

Is it possible to show the flow in more detail in R?

library("remotes")
remotes::install_github("davidsjoberg/ggsankey")
library(ggsankey)


data_sankey <- common_data_0y_1y_5y[c("ID", "meets_criteria_0y", "meets_criteria", "meets_criteria_5y")]

df <- data_sankey%>%
  make_long(meets_criteria_0y, meets_criteria, meets_criteria_5y)


ggplot(df, aes(
  x = x,
  next_x = next_x,
  node = node,
  next_node = next_node,
  fill = factor(node),
  label = node
)) +
  geom_sankey(
    flow.alpha = 0.3,
    node.color = "black"
  ) +
  theme_sankey(base_size = 16) +
  scale_fill_manual(
    values = c("0" = "#FF6347", "1" = "#00CED1"),
    labels = c("0" = "Don't meet criteria", "1" = "Meet criteria")
  ) +
  guides(fill = guide_legend(title = "legend"))+
  scale_x_discrete(labels = c("start", "1 year", "5 year"))+
  ggtitle("flow in meeting criteria after start medication")+
  theme(plot.title = element_text(size = 14, hjust = 0.4),
        legend.text = element_text(size = 12))

Does anyone here know if and how that is possible?

Kind regards,

Gerjan

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.