0

I have made an alluvial plot with ggplot, but I'm finding it's difficult to distinguish between the boxes. I do not want to change how it's coloured, but I am hoping to increase the line width around each box so they are more distinguished.

Here is a sample of my dataframe

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))

and here is the code I am using

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

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, alpha = 0.2, reverse = TRUE, color = "black") +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), size= 5, color = "black") +
  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())

I do not want to change the width of lines BETWEEN boxes, I just want to change the width of border lines for the boxes or stratum on right and left side of the graph. Any ideas?

Kristen Cyr
  • 629
  • 5
  • 16

1 Answers1

2

You could set the width of the border lines via linewidth in geom_stratum:

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

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, alpha = 0.2, reverse = TRUE, color = "black", linewidth = 2) +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), size = 5, color = "black") +
  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

stefan
  • 90,330
  • 6
  • 25
  • 51