我已经使用Likert包创建了一些图表,但是当我按组创建图时,plot.percents = TRUE不会为我提供每个响应类别的标签。plot.percents.high = TRUE和plot.percents.low = TRUE为我提供了组合百分比,但是我希望所有响应类别都使用它。它可以很好地与未分组的数据一起使用。我使用的代码是:
做一些数据
library(likert)
library (reshape)
Group <- c("Group 1", "Group 1", "Group 1", "Group 1", "Group 1", "Group 1", "Group 1", "Group 2", "Group 2", "Group 2", "Group 2", "Group 2",
"Group 2","Group 2", "Group 3", "Group 3", "Group 3", "Group 3","Group 3","Group 3","Group 3")
Var1 <- c("Agree", "Agree", "Strongly agree", "Agree", "Strongly disagree", "Agree","Strongly agree", "Disagree", "Strongly agree",
"Strongly agree", "Agree", "Disagree", "Agree", "Strongly disagree", "Agree", "Agree", "Agree", "Disagree", "Strongly agree",
"Strongly disagree", "Strongly agree")
df <- as.data.frame (cbind(Group, Var1))
Variable <- c("Var1")
df2 <- (df[Variable])
likert.df <- likert (df2)
likert.df.group <- likert (df2, grouping=df$Group)
Run Code Online (Sandbox Code Playgroud)
likert.df是所有人的响应,likert.df.group是每个组的响应。当我仅用likert.df运行该图(如下)时,我得到每个响应的百分比,当我为likert.df.group运行它时,它们消失了。
likert.bar.plot(likert.df, low.color = "#007CC2",
high.color = "#F7971C", neutral.color = "grey90",
neutral.color.ramp = "white", plot.percent.low = FALSE,
plot.percent.high = FALSE, plot.percent.neutral = FALSE,
plot.percents = TRUE, text.size = 4,
text.color = "black", centered = FALSE,
include.center = FALSE, ordered = FALSE,
wrap.grouping = 50, legend = "Response",
legend.position = "bottom", panel.arrange = "v",
panel.strip.color = "grey90")+
ggtitle("Chart Title") +
theme (panel.background = element_rect(fill="NA")) +
theme (axis.text.y = element_text (colour="black", size="10", hjust=0))+
theme (axis.text.x = element_text (colour="black", size="10")) +
theme (legend.title = element_blank())+
theme (plot.margin = unit (c(0,0,0,0),"mm"))
Run Code Online (Sandbox Code Playgroud)
我想念什么吗?
嘿,我尝试了一下,但使用分组数据对我来说不起作用。没有提及为什么尽管plot.percent.low并且plot.percent.high工作正常。除非其他人破解它,我所能做的就是提供一个解决方法,使用plot()而不是 likert.bar.plot和text()
在这里,我仅标记Agree所有三个组的类别。
plot(likert.df.group, type="bar")
text(c(0.35,0.35,0.35), c(0.85,0.6,0.25),
labels = paste0(c(42.8,28.57,42.85),"%") )
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
2866 次 |
| 最近记录: |