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
版权声明:本文标题:r - Aluvial Graph Color, Label, and Ordering Issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306283a1932900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论