Closed bridgeovertroubledhuman closed 3 months ago
Hi @bridgeovertroubledhuman, have you tried using the flow stat rather than the alluvium stat? (See documentation here.) If i understand you correctly, then it's exactly what you're after.
Oh thank you so much! I had no idea it works like this. Yes, I wanted a "memoryless flow"!
thisiswhatiwanted <- ggplot(data = titanic_wide,
aes(axis1 = Class,
axis2 = Survived,
axis3 = Age,
y = Freq)) +
scale_x_discrete(limits = c("Class", "Survived", "Age Group"), expand = c(.2, .05)) +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
geom_flow(aes(fill = Survived), show.legend = FALSE) +
theme_minimal() +
ggtitle("Passengers on the maiden voyage of the Titanic",
"by survival")
Sorry @corybrunson there is one thing I cannot wrap my head around:
Why are the stratums/strata(?) colored with the colors from the alluvium (when you don't set the alpha of geom_stratum
to 1) but the stratums are always white when you use a geom_flow
instead of geom_alluvium
?
Given the example here, on the page you linked before it seems to be dependent on the data format, i.e. if axis1, axis2, and axis3 are defined or if there are aes like these: aes(x = survey, stratum = response, alluvium = subject, y = freq, fill = response). However, I am not managing to replicate that behavior, so I just think, I might be missing something.
Thank you!
There are two behaviors at work here:
alluvium = subject
and stratum = response
. They will only be colored when the fill
aesthetic is passed the same variable.Does that clear it up?
Thank you. Yeah, from both texts I didn't get the answer - however, in case someone else has the problem, this is my solution, to when you want geom_flows with lodes based on another variables and your data is in axis1 axis2 axis3 format, you'll need geom_stratum with no options, and geom_lode with the correct filling.
ggplot(data = titanic_wide, aes(axis1 = Class, axis2 = Survived, axis3 = Age, y = Freq)) + scale_x_discrete(limits = c("Class", "Survived", "Age Group") ,expand = c(.2, .05) ) + geom_stratum() + geom_lode(aes(fill = Survived), show.legend = FALSE) + geom_text(stat = "stratum", aes(label = after_stat(stratum))) + geom_flow(aes(fill = Survived), show.legend = FALSE) + theme_minimal() + ggtitle("Passengers on the maiden voyage of the Titanic", "by survival")
See the image below: solution.pdf
I want to create one plot like this
However, after examining the data, I realized the many lines don't help me as much as I would have helped (i.e., from the plot I had no idea that there were children in the second class that survived). So I think, for my purpose a plot like this on the left
and this on the right
Would be better. I try to show it in the picture below. Is this possible with the
ggaluvial
function?