カテゴリー変数 (1 から 5 のスケールでの顧客満足度) に一連の積み上げバー チャットをプロットしようとしています。1 から 5 までのグループを表示したいと思います。しかし、R は積み上げ棒グラフをデータ値ではなくデータ ラベルでグループ化します。
誰かが私がチャートのどこを間違えたのか教えてくれませんか? ggplot は、満足度 (1 から 5) をデータ ラベル (1 から 5 ではなくアルファベット順) で集計しました。満足度を 1 から 5 の正しい順序でプロットするように R に指示するにはどうすればよいですか (非常に不満から非常に満足)
申し訳ありませんが、私はまだ新しいので、画像をアップロードする権限がありません。グラフを表示するには、コードを実行する必要があるかもしれません。
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)