0

我正在尝试在分类变量上绘制一系列堆叠的条形聊天(客户满意度为 1 到 5)。我想显示从 1 到 5 的组。但是,R 按数据标签而不是数据值对堆积条形图进行分组。

谁能指出我在图表上做错了什么。ggplot 按其数据标签(按字母顺序而不是从 1 到 5)汇总了满意度(从 1 到 5)。我如何告诉 R 以从 1 到 5 的正确顺序绘制满意度(高度不满意到高度满意)

对不起,我还很新鲜,我没有上传图片的权限。您可能需要运行代码来查看图表。

x8.p.m <-structure(list(Var.1 = structure(c(2L, 4L, 5L, 3L, 1L, 2L, 4L, 
5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 
3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 
1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 
2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 
4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 
5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 
3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 
1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 
2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L, 2L, 4L, 5L, 3L, 1L), .Label = c("Extremely Dis-Satistfied", 
"Highly Satisfied", "Moderately Dis-Satisfied", "Moderately Satisfied", 
"Satisfied"), class = "factor"), Var.2 = structure(c(1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 
4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 
5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 
5L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 
6L, 6L, 6L, 6L), .Label = c("I've changed for work/ a new job/ gone on a work plan", 
"I want a phone that 2degrees doesn't offer", "I want Best Mates/ Favourites", 
"I was offered or saw a better offer on another network", "Issues with the 2degrees network (poor coverage)", 
"Other"), class = "factor"), YearQuarter = structure(c(15218, 
15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 
15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 
15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 15218, 
15218, 15218, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 
15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 
15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 
15309, 15309, 15309, 15309, 15309, 15400, 15400, 15400, 15400, 
15400, 15400, 15400, 15400, 15400, 15400, 15400, 15400, 15400, 
15400, 15400, 15400, 15400, 15400, 15400, 15400, 15400, 15400, 
15400, 15400, 15400, 15400, 15400, 15400, 15400, 15400, 15492, 
15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 
15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 
15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 15492, 
15492, 15492, 15584, 15584, 15584, 15584, 15584, 15584, 15584, 
15584, 15584, 15584, 15584, 15584, 15584, 15584, 15584, 15584, 
15584, 15584, 15584, 15584, 15584, 15584, 15584, 15584, 15584, 
15584, 15584, 15584, 15584, 15584), class = "Date"), value = c(70, 
20, 7, 2, 2, 54, 33, 8, 0, 4, 37, 29, 23, 11, 0, 46, 29, 18, 
4, 2, 16, 29, 26, 20, 10, 37, 20, 9, 13, 22, 66, 18, 14, 2, 0, 
65, 20, 12, 3, 0, 47, 29, 18, 4, 3, 48, 32, 16, 3, 1, 24, 25, 
19, 22, 10, 41, 14, 18, 9, 18, 66, 25, 6, 3, 0, 62, 23, 14, 1, 
0, 47, 30, 14, 8, 1, 46, 31, 16, 6, 1, 19, 27, 25, 22, 7, 34, 
15, 17, 13, 21, 68, 22, 7, 2, 1, 62, 21, 16, 1, 0, 45, 30, 18, 
5, 1, 43, 28, 22, 5, 2, 20, 23, 25, 23, 10, 36, 20, 12, 14, 19, 
60, 25, 13, 2, 0, 62, 23, 10, 6, 0, 41, 24, 26, 9, 0, 47, 31, 
16, 5, 1, 13, 29, 22, 24, 13, 28, 16, 20, 18, 18)), .Names = c("Var.1", 
"Var.2", "YearQuarter", "value"), row.names = c(NA, -150L), class = "data.frame")
> 

ggplot(data=x8.p.m, aes(x=YearQuarter, y=value, fill=Var.1)) + geom_bar(stat="identity",position="stack")+facet_wrap(~Var.2)
4

1 回答 1

0

首先检查您的因子水平:

levels(x8.p.m$Var.1)

然后查看这篇博文:链接-点击这里-

PS这不是ggplot2问题,因为您将在帖子中阅读。

于 2012-11-11T04:42:13.477 回答