Alluvial Charts - Flow does not appear

Asked

Viewed 34 times

2

I have a table like this:

Organization    Timeframe   Code                    id
1   Agencia1    Fortnight 1 International Affairs   1
2   Agencia2    Fortnight 1 Environment             2
3   Agencia2    Fortnight 1 Health                  4
4   Agencia2    Fortnight 1 Public Policy           5
5   Agencia1    Fortnight 2 Politics                6
6   Agencia2    Fortnight 2 Disaster                7
7   Agencia1    Fortnight 2 Public Policy           8
8   Agencia1    Fortnight 2 Federal Government      9
9   Agencia1    Fortnight 2 Business                10
10  Agencia1    Fortnight 3 Federal Government      11
11  Agencia2    Fortnight 3 Dissemination - COVID19 12
12  Agencia1    Fortnight 3 Transparency - COVID19  13
13  Agencia2    Fortnight 3 Economy - COVID19       14
14  Agencia1    Fortnight 3 Prevention - COVID19    15
15  Agencia1    Fortnight 4 Economy                 16
16  Agencia1    Fortnight 4 Media                   17
17  Agencia1    Fortnight 4 Leisure                 18
18  Agencia1    Fortnight 4 Politics                19
19  Agencia1    Fortnight 4 Prevention - COVID19    20
20  Agencia1    Fortnight 5 Prevention - COVID19    21

I would like to do an alluvial Chart that shows the different topics of each organization in every fortnight (Fortnight). I created a chart with what I would like, but the streams I would link (with a color for each organization) I’m not showing up. Does anyone know how to help me?

enter image description here

The code of what I did is this:

alluvial_data <- as.data.frame(FC_Outlets %>%select(Organization, Timeframe, Code))
alluvial_data <- alluvial_data %>% mutate(id = row_number())

#Remove duplicates
alluvial_data <- alluvial_data %>% 
  distinct(Organization, Timeframe, Code, .keep_all = TRUE)


# Convert Timeframe to Factor - Categorical Variable
alluvial_data$Timeframe <-as.factor(alluvial_data$Timeframe)

# Convert Code to String
alluvial_data$Code <-as.character(alluvial_data$Code)

library(RColorBrewer)

# Define the number of colors you want
nb.cols <- 10
mycolors <- colorRampPalette(brewer.pal(8, "Set2"))(nb.cols)


# Chart
ggplot(alluvial_data,
       aes(x = Timeframe, stratum = Code, alluvium = id,
           fill = Code, label = Code)) +
  #scale_fill_brewer(type = "qual", palette = "Set2") +
  scale_fill_manual(values = mycolors) +
  geom_flow(stat = "alluvium", lode.guidance = "frontback",
            color = "darkgray") +
  geom_stratum() +
  theme(legend.position = "bottom") +
  ggtitle("Organizations")

Thank you

  • 1

    Welcome to Stackoverflow! Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please take a look at this link (mainly in the use of function dput) and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.