If I have a dataframe in R (called connections_df), that shows the connections between the two endpoints (endpoint1 and endpoint2) with the corresponding chromosome (CHR):
endpoint1 endpoint2 CHR total_connections
<chr> <chr> <dbl> <int>
1 Acute Ulceration Body Image 6 1
2 Acute Ulceration Breast Symptoms 6 1
3 Acute Ulceration RILA 17 1
4 Acute Ulceration Telangiectasia G1 6 1
5 Acute desqumation Acute Ulceration 2 20
6 Acute desqumation Acute Ulceration 5 20
7 Acute desqumation Acute Ulceration 6 20
8 Acute desqumation Acute Ulceration 8 20
9 Acute desqumation Acute Ulceration 9 20
10 Acute desqumation Acute Ulceration 10 20
I plot this data using a sankey diagram using ggplot. The code is below. I notice however my plot looks squished, you cannot see the labels for some of the endpoints. Is there a way to fit everything in the plot so its easier to see because right now the top endpoints Acute desqumation Acute Ulceration take so much space (because the links represent / are proportional to the total_connectons). Is there a way to scale it so everything fits. I’ve even tried ggsave and set the width and height and yet still the plot is not scaled properly.
Code:
sankey <- ggplot(data = connections_df,
aes(axis1 = endpoint1, axis2 = endpoint2, y = total_connections / 10)) +
geom_alluvium(aes(fill = CHR)) +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Endpoint 1", "Endpoint 2"), expand = c(0.1, 0.1)) +
scale_fill_viridis(discrete = TRUE, name = "Chromosome") +
theme_minimal() +
labs(title = "Sankey Plot of Endpoint Connections by Chromosome",
x = NULL,
y = "Number of Connections")
Plot picture: you can see the labels for the endpoints at the bottom right is very squished.