paola cornejo
paola cornejo

Reputation: 13

How to change transparency in geom_flow ggplot?

I am trying to change the transparency of the flow elements of an alluvial plot. I know I should change the value of 'alpha' but I am not sure where in the code I have to add this parameter. The following is my code:

library(ggplot2)
library(ggalluvial)

ggplot(sp.alluvial, aes(x = stage, stratum = state, alluvium = pks, fill = state, label = state)) +
  scale_fill_brewer(type = "qual", palette = "Set2") +
  geom_flow(stat = "alluvium", lode.guidance = "frontback", aes(fill = state), aes.flow = "backward") + 
  geom_stratum() +
  theme(legend.position = "bottom", axis.text.y = element_blank(), axis.ticks.y = element_blank()) 

I have tried the next options:

geom_flow(stat = "alluvium", lode.guidance = "frontback", aes(fill = state), aes.flow = "backward", alpha = 0.6)

geom_flow(stat = "alluvium", lode.guidance = "frontback", aes(fill = state, alpha = 0.6), aes.flow = "backward")

and

+ geom_density(alpha = 0.6)

Any ideas?

Thanks!

Upvotes: 1

Views: 877

Answers (1)

Rui Barradas
Rui Barradas

Reputation: 76402

The following seems to work.
The plot is based on the second example in geom_lode, since the question does not have a posted data set.

I have plotted the same with different values of the alpha argument, 0.2 and 0.8, and the flows' transparency does change.

library(ggplot2)
library(ggalluvial)

gg <- ggplot(as.data.frame(Titanic),
             aes(y = Freq, 
                 axis1 = Class, axis2 = Sex, axis3 = Age,
                 fill = Survived))

gg + 
  geom_flow(alpha = 0.5) + 
  geom_stratum() + 
  geom_lode() + 
  geom_text(stat = "stratum", infer.label = TRUE)

enter image description here

Upvotes: 1

Related Questions