These are my data:
molec_freq<-structure(list(Primary = c("Basal-Like", "Basal-Like", "Basal-Like",
"Basal-Like", "HER2-Enriched", "HER2-Enriched", "HER2-Enriched",
"HER2-Enriched", "HER2-Enriched", "Luminal A", "Luminal A", "Luminal A",
"Luminal A", "Luminal A", "Luminal A", "Luminal A", "Luminal A",
"Luminal B", "Luminal B", "Luminal B", "Luminal B", "Luminal B",
"Luminal B", "Luminal B"), Metastatic = c(".Basal-Like", ".Basal-Like",
".HER2-Enriched", ".Luminal B", ".Basal-Like", ".Basal-Like",
".HER2-Enriched", ".HER2-Enriched", ".Luminal A", ".Basal-Like",
".HER2-Enriched", ".HER2-Enriched", ".Luminal A", ".Luminal A",
".Luminal B", ".Luminal B", ".Luminal B", ".Basal-Like", ".HER2-Enriched",
".Luminal A", ".Luminal A", ".Luminal B", ".Luminal B", ".Luminal B"
), Race = c("AA", "Caucasian", "Caucasian", "Caucasian", "AA",
"Caucasian", "AA", "Caucasian", "Caucasian", "Caucasian", "AA",
"Caucasian", "AA", "Caucasian", "AA", "Asian", "Caucasian", "Caucasian",
"Caucasian", "AA", "Caucasian", "AA", "Asian", "Caucasian"),
Freq = c(8L, 11L, 1L, 1L, 1L, 1L, 2L, 8L, 1L, 1L, 1L, 4L,
1L, 5L, 1L, 1L, 11L, 2L, 1L, 1L, 4L, 6L, 2L, 13L)), row.names = c(NA,
-24L), class = "data.frame")
This is the code I'm using right now to make my plot:
ggplot(data = molec_freq,
aes(axis1=Primary, axis2=Metastatic, y=Freq)) +
scale_x_discrete(limits=c("Primary", "Metastatic")) +
xlab("Tumor site") +
geom_alluvium(aes(fill = Race)) +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
ggtitle("Primary and Metastatic molecular subtype") +
theme_minimal()
I know that I can color the stratum using the color of the connecting lines like this:
ggplot(data = molec_freq,
aes(axis1=Primary, axis2=Metastatic, y=Freq)) +
scale_x_discrete(limits=c("Primary", "Metastatic")) +
xlab("Tumor site") +
geom_alluvium(aes(fill = Race)) +
geom_stratum(aes(fill = after_stat(stratum))) +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
ggtitle("Primary and Metastatic molecular subtype") +
theme_minimal() +
scale_fill_manual(values = c(AA = "#F8766D", Asian = "#490092", Caucasian = "#00BFC4"),
na.value = NA)
But I want to color the stratum based on a separate condition (so they'll be a different color than the flow lines). I have 88 samples and each one has a congruent or incongruent label for both primary and met. Example:
Subtype.Congruence.Primary Subtype.Congruence..met.
1 Incongruent Incongruent
2 Congruent Congruent
3 Incongruent Incongruent
4 Congruent Congruent
5 Congruent Congruent
6 Congruent Congruent
I want to color the lines in each stratum box by this congruent or incongruent label. But I'm not even sure if I can do that because the flow lines are based on number of samples meeting that condition rather than each individual sample. Any help would be greatly appreciated!