我的数据(来自李克特量表问题)如下所示:
head(dat)
Consideration Importance2 Importance Percent Count
1 Aesthetic value 1 Not at all important 0.046875 3
2 Aesthetic value 2 Of little importance 0.109375 7
3 Aesthetic value 3 Moderately important 0.250000 16
dput(head(dat,6))
structure(list(Consideration = structure(c(2L, 2L, 2L, 2L, 2L,
12L), .Label = c("", "Aesthetic value", "Affordability/cost-efficiency",
"Climate change reduction", "Eco-sourcing", "Ecosystem services provision",
"Erosion mitigation", "Habitat for native wildlife", "Habitat/species conservation",
"Human use values", "Increasing biodiversity", "Planting native species",
"Restoring ecosystem function", "Restoring to a historical state"
), class = "factor"), Importance2 = c(1L, 2L, 3L, 4L, 5L, 1L),
Importance = structure(c(4L, 5L, 3L, 2L, 6L, 4L), .Label = c("",
"Important", "Moderately important", "Not at all important",
"Of little importance", "Very Important"), class = "factor"),
Percent = c(0.046875, 0.109375, 0.25, 0.375, 0.234375, 0),
Count = c(3L, 7L, 16L, 24L, 15L, 0L), percentage = c(5L,
11L, 25L, 38L, 23L, 0L)), row.names = c(NA, 6L), class = "data.frame")
我使用堆积条形图绘制了结果。我想知道如何修改它,使它成为一个发散的堆积条形图,如下图所示,以 Importance2 级别 3(中等重要)为中心。
我知道有一个名为 likert 的包可以用于此,但我认为我的数据格式不正确。
我现有情节的代码是:
ggplot(dat, aes(x = Consideration, y = Percent, fill = forcats::fct_rev(Importance2))) +
geom_bar(position="fill", stat = "identity", color = "black", size = 0.2, width = 0.8) +
aes(stringr::str_wrap(dat$Consideration, 34), dat$Percent) +
coord_flip() +
labs(y = "Percentage of respondents (%)") +
scale_y_continuous(breaks=c(0, 0.25, 0.50, 0.75, 1), labels=c("0", "25", "50", "75", "100")) +
theme(axis.title.y=element_blank(), panel.background = NULL, axis.text.y = element_text(size=8), legend.title = element_text(size=8), legend.text = element_text(size = 6)) +
scale_fill_manual(name="Scale", breaks=c("1", "2", "3", "4", "5"), labels=c("Not at all important", "Of little importance", "Moderately important","Important", "Very important"), values=col3)