Search code examples
rggalluvial

Changing alpha/transparency of alluvial plot in ggplot R?


I have made an alluvial plot, but the colours are too transparent. I tried playing around with alpha = in my code but nothing happens. This is the code I'm using. I kept the alpha = in my code where I have tried it to you can see, but I have tried it with just one, and both, and one or the other etc.

library(dplyr)
library(ggplot2)
library("ggalluvial")
library("viridis")

plot = ggplot(df,
       aes(y = Total_Publications, axis1 = Method_Group, axis2 = Topic)) +
  geom_alluvium(aes(fill = Topic, alpha = 1), width = 1/5) +
  scale_fill_viridis(discrete=TRUE, alpha = 1) +
  geom_stratum(width = 1/5, alpha = 0, reverse = TRUE, color = "black") +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), size= 4.5) +
  scale_x_discrete(limits = c("Ecological Topic", "Ecological Theme"), expand = c(.05, .05)) +
  theme_minimal() +
  theme(axis.title.y = element_blank(), axis.text.y= element_blank(), legend.position = "none", 
        plot.title = element_text(hjust=0.5, size=18), axis.text.x = element_blank())

Here is a sample of my data

df = structure(list(Theme = c("Adult migration", "Adult migration", 
"Adult migration", "Adult migration", "Adult migration", "Aquaculture", 
"Aquaculture", "Artificial Reefs", "Attributing behaviours to movement", 
"Attributing behaviours to movement", "Attributing behaviours to movement", 
"Attributing behaviours to movement", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Co_existence", "Co_existence", 
"Co_existence", "Co_existence", "Commercial species", "Commercial species", 
"Commercial species", "Commercial species", "Community structuring", 
"Community structuring", "Cooperative Behaviour", "Demographics"
), Tracking_Group = c(Animalborne_Satellite_Archival = "NoReceiver", 
Stationary_Radio = "NoReceiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Stationary_Acoustic_Radio_PIT = "Receiver", 
Stationary_Acoustic = "Receiver", Stationary_Acoustic = "Receiver", 
Controlled_Acoustic = "Receiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Stationary_Radio_PIT = "Receiver", BRUV_Acoustic_Satellite = "Both", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Satellite_Archival = "NoReceiver", Controlled_Archival = "NoReceiver", 
Stationary_Archival = "NoReceiver", Stationary_Archival = "NoReceiver", 
Stationary_Satellite = "NoReceiver", Animalborne_Acoustic = "Receiver", 
Animalborne_Acoustic_Archival = "Receiver", BRUV_Acoustic = "Receiver", 
BRUV_Acoustic = "Receiver", Controlled_Acoustic = "Receiver", 
Controlled_Acoustic = "Receiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Animalborne_Archival = "NoReceiver", 
Animalborne_Archival = "NoReceiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Stationary_Archival = "NoReceiver", 
BRUV_Acoustic = "Receiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic_Archival = "Receiver", BRUV_Acoustic = "Receiver", 
BRUV_Acoustic = "Receiver", Animalborne_Archival = "NoReceiver", 
BRUV_Acoustic_Satellite = "Both"), Combination = c("Animalborne_Satellite_Archival", 
"Stationary_Radio", "Stationary_Acoustic", "Stationary_Acoustic", 
"Stationary_Acoustic_Radio_PIT", "Stationary_Acoustic", "Stationary_Acoustic", 
"Controlled_Acoustic", "Animalborne_Archival", "Animalborne_Archival", 
"Animalborne_Archival", "Stationary_Radio_PIT", "BRUV_Acoustic_Satellite", 
"Animalborne_Archival", "Animalborne_Archival", "Animalborne_Archival", 
"Animalborne_Archival", "Animalborne_Archival", "Animalborne_Archival", 
"Animalborne_Archival", "Animalborne_Archival", "Animalborne_Archival", 
"Animalborne_Archival", "Animalborne_Satellite_Archival", "Controlled_Archival", 
"Stationary_Archival", "Stationary_Archival", "Stationary_Satellite", 
"Animalborne_Acoustic", "Animalborne_Acoustic_Archival", "BRUV_Acoustic", 
"BRUV_Acoustic", "Controlled_Acoustic", "Controlled_Acoustic", 
"Stationary_Acoustic", "Stationary_Acoustic", "Stationary_Acoustic", 
"Stationary_Acoustic", "Animalborne_Archival", "Animalborne_Archival", 
"Stationary_Acoustic", "Stationary_Acoustic", "Stationary_Archival", 
"BRUV_Acoustic", "Stationary_Acoustic", "Stationary_Acoustic_Archival", 
"BRUV_Acoustic", "BRUV_Acoustic", "Animalborne_Archival", "BRUV_Acoustic_Satellite"
), Total_Publications = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Topic = c("Reproductive Ecology", 
"Reproductive Ecology", "Reproductive Ecology", "Reproductive Ecology", 
"Reproductive Ecology", "Fisheries Managemenet", "Landuse Management", 
"Conservation Methods", "Methodological", "Methodological", "Methodological", 
"Methodological", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Fisheries Managemenet", "Fisheries Managemenet", 
"Fisheries Managemenet", "Fisheries Managemenet", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Other Drivers of Movement and Habitat Use"
), Method_Group = c("Animalborne_NoReceiver", "Stationary_NoReceiver", 
"Stationary_Receiver", "Stationary_Receiver", "Stationary_Receiver", 
"Stationary_Receiver", "Stationary_Receiver", "Controlled_Receiver", 
"Animalborne_NoReceiver", "Animalborne_NoReceiver", "Animalborne_NoReceiver", 
"Stationary_Receiver", "BRUV_Both", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Animalborne_NoReceiver", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Animalborne_NoReceiver", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Animalborne_NoReceiver", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Controlled_NoReceiver", "Stationary_NoReceiver", 
"Stationary_NoReceiver", "Stationary_NoReceiver", "Animalborne_Receiver", 
"Animalborne_Receiver", "BRUV_Receiver", "BRUV_Receiver", "Controlled_Receiver", 
"Controlled_Receiver", "Stationary_Receiver", "Stationary_Receiver", 
"Stationary_Receiver", "Stationary_Receiver", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Stationary_Receiver", "Stationary_Receiver", 
"Stationary_NoReceiver", "BRUV_Receiver", "Stationary_Receiver", 
"Stationary_Receiver", "BRUV_Receiver", "BRUV_Receiver", "Animalborne_NoReceiver", 
"BRUV_Both")), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -50L), groups = structure(list(Theme = c("Adult migration", 
"Adult migration", "Adult migration", "Adult migration", "Aquaculture", 
"Aquaculture", "Artificial Reefs", "Attributing behaviours to movement", 
"Attributing behaviours to movement", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Behavioural states and adaptations", "Behavioural states and adaptations", 
"Co_existence", "Co_existence", "Commercial species", "Commercial species", 
"Commercial species", "Commercial species", "Community structuring", 
"Cooperative Behaviour", "Demographics"), Topic = c("Reproductive Ecology", 
"Reproductive Ecology", "Reproductive Ecology", "Reproductive Ecology", 
"Fisheries Managemenet", "Landuse Management", "Conservation Methods", 
"Methodological", "Methodological", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Behavioural Ecology", 
"Behavioural Ecology", "Behavioural Ecology", "Fisheries Managemenet", 
"Fisheries Managemenet", "Fisheries Managemenet", "Fisheries Managemenet", 
"Behavioural Ecology", "Behavioural Ecology", "Other Drivers of Movement and Habitat Use"
), Tracking_Group = c(Animalborne_Satellite_Archival = "NoReceiver", 
Stationary_Radio = "NoReceiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic_Radio_PIT = "Receiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Controlled_Acoustic = "Receiver", 
Animalborne_Archival = "NoReceiver", Stationary_Radio_PIT = "Receiver", 
BRUV_Acoustic_Satellite = "Both", Animalborne_Archival = "NoReceiver", 
Animalborne_Satellite_Archival = "NoReceiver", Controlled_Archival = "NoReceiver", 
Stationary_Archival = "NoReceiver", Stationary_Satellite = "NoReceiver", 
Animalborne_Acoustic = "Receiver", Animalborne_Acoustic_Archival = "Receiver", 
BRUV_Acoustic = "Receiver", Controlled_Acoustic = "Receiver", 
Stationary_Acoustic = "Receiver", Animalborne_Archival = "NoReceiver", 
Stationary_Acoustic = "Receiver", Stationary_Archival = "NoReceiver", 
BRUV_Acoustic = "Receiver", Stationary_Acoustic = "Receiver", 
Stationary_Acoustic_Archival = "Receiver", BRUV_Acoustic = "Receiver", 
Animalborne_Archival = "NoReceiver", BRUV_Acoustic_Satellite = "Both"
), Combination = c("Animalborne_Satellite_Archival", "Stationary_Radio", 
"Stationary_Acoustic", "Stationary_Acoustic_Radio_PIT", "Stationary_Acoustic", 
"Stationary_Acoustic", "Controlled_Acoustic", "Animalborne_Archival", 
"Stationary_Radio_PIT", "BRUV_Acoustic_Satellite", "Animalborne_Archival", 
"Animalborne_Satellite_Archival", "Controlled_Archival", "Stationary_Archival", 
"Stationary_Satellite", "Animalborne_Acoustic", "Animalborne_Acoustic_Archival", 
"BRUV_Acoustic", "Controlled_Acoustic", "Stationary_Acoustic", 
"Animalborne_Archival", "Stationary_Acoustic", "Stationary_Archival", 
"BRUV_Acoustic", "Stationary_Acoustic", "Stationary_Acoustic_Archival", 
"BRUV_Acoustic", "Animalborne_Archival", "BRUV_Acoustic_Satellite"
), Method_Group = c("Animalborne_NoReceiver", "Stationary_NoReceiver", 
"Stationary_Receiver", "Stationary_Receiver", "Stationary_Receiver", 
"Stationary_Receiver", "Controlled_Receiver", "Animalborne_NoReceiver", 
"Stationary_Receiver", "BRUV_Both", "Animalborne_NoReceiver", 
"Animalborne_NoReceiver", "Controlled_NoReceiver", "Stationary_NoReceiver", 
"Stationary_NoReceiver", "Animalborne_Receiver", "Animalborne_Receiver", 
"BRUV_Receiver", "Controlled_Receiver", "Stationary_Receiver", 
"Animalborne_NoReceiver", "Stationary_Receiver", "Stationary_NoReceiver", 
"BRUV_Receiver", "Stationary_Receiver", "Stationary_Receiver", 
"BRUV_Receiver", "Animalborne_NoReceiver", "BRUV_Both"), .rows = structure(list(
    1L, 2L, 3:4, 5L, 6L, 7L, 8L, 9:11, 12L, 13L, 14:23, 24L, 
    25L, 26:27, 28L, 29L, 30L, 31:32, 33:34, 35:38, 39:40, 41:42, 
    43L, 44L, 45L, 46L, 47:48, 49L, 50L), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -29L), .drop = TRUE))

Any ideas how to make it less transparent?


Solution

  • Are you looking for this?

    ggplot(df, aes(y = Total_Publications, axis1 = Method_Group, axis2 = Topic)) +
      geom_alluvium(aes(fill = Topic, color = after_scale(fill)), 
                    width = 1/5, alpha = 1) +
      scale_fill_viridis(discrete=TRUE) +
      geom_stratum(width = 1/5, reverse = TRUE, color = "black") +
      geom_text(stat = "stratum", aes(label = after_stat(stratum)), size= 4.5) +
      scale_x_discrete(limits = c("Ecological Topic", "Ecological Theme"), 
                       expand = c(.05, .05)) +
      theme_minimal() +
      theme(axis.title.y = element_blank(), 
            axis.text.y= element_blank(), 
            legend.position = "none", 
            plot.title = element_text(hjust=0.5, size=18), 
            axis.text.x = element_blank())
    

    enter image description here