admin管理员组

文章数量:1122832

I'm trying to produce a Sankey plot, but every time I code it, either the left or right side ends up without color. Also, I'm having trouble getting correct the strongly agree, agree, neither, disagree, strongly disagree order.

Here's what I have:

data$sexismgrid_5[data$sexismgrid_5==1] <- "Strongly agree"
data$sexismgrid_5[data$sexismgrid_5==4] <- "Agree"
data$sexismgrid_5[data$sexismgrid_5==5] <- "Neither agree nor disagree"
data$sexismgrid_5[data$sexismgrid_5==6] <- "Disagree"
data$sexismgrid_5[data$sexismgrid_5==7] <- "Disagree strongly"
data$sexismgrid_6[data$sexismgrid_6==1] <- "Strongly agree"
data$sexismgrid_6[data$sexismgrid_6==4] <- "Agree"
data$sexismgrid_6[data$sexismgrid_6==5] <- "Neither agree nor disagree"
data$sexismgrid_6[data$sexismgrid_6==6] <- "Disagree"
data$sexismgrid_6[data$sexismgrid_6==7] <- "Disagree strongly"

transition_matrix <- table(data$sexismgrid_5, data$sexismgrid_6)

library(ggalluvial)

transition_data <- data.frame(sexismgrid_5 = data$sexismgrid_5,sexismgrid_6 = data$sexismgrid_6)

Sankey Plot

ggplot(transition_data, aes(axis1 = sexismgrid_5, axis2 = sexismgrid_6)) +
     geom_alluvium(aes(fill = sexismgrid_5)) +
     geom_stratum(aes(fill = sexismgrid_5)) +
     geom_stratum(aes(fill = sexismgrid_6)) +
     scale_x_discrete(limits = c("Question 5", "Question 6"), expand = c(0.15, 0.15)) +
     scale_fill_manual(values = c("Strongly agree" = "lightblue","Agree" = "lightgreen","Neither agree nor disagree" = "lightyellow","Disagree" = "violet","Disagree strongly" = "pink")) +
     labs(title = "Changes in Responses Between Question 5 and Question 6",x = "Question", y = "Count of Respondents") +
     theme_void()`

本文标签: rAluvial Graph Colorlabeland Ordering IssuesStack Overflow