改变冲积地块边界线的宽度,ggplot R?

moiiocjp  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(120)

我用ggplot绘制了一个冲积图,但是我发现很难区分方框。我不想改变它的颜色,但是我希望增加每个方框周围的线宽,这样它们就更容易区分了。
下面是我的 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))

这是我使用的代码

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

我不想改变框之间的线的宽度,我只想改变框的边界线的宽度或stratum在右边和左边的图形。任何想法?

8i9zcol2

8i9zcol21#

您可以通过geom_stratum中的linewidth设置边框线的宽度:

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

相关问题