0
我有一些數據以相同的方式構造成執行以下操作:分組條形圖GGPLOT2
structure(list(respectfromsuperior = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, NA, 2L, 1L, 1L, 1L, 1L, 2L), .Label = c("agree",
"disagree"), class = "factor"), respectideserve = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L), .Label = c("agree",
"disagree"), class = "factor"), undesirablechange = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, NA, 2L, 2L,
2L, 2L, 2L, 1L, 1L, NA, 1L, 2L, 1L, 2L, 2L, 2L), .Label = c("agree",
"disagree"), class = "factor"), jobsecuritypoor = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("agree",
"disagree"), class = "factor"), promotionprospectsadequate = structure(c(2L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L), .Label = c("agree",
"disagree"), class = "factor"), salaryadequate = structure(c(2L,
1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("agree",
"disagree"), class = "factor"), branch = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Edinburgh",
"Head Office", "Manchester"), class = "factor")), .Names = c("respectfromsuperior",
"respectideserve", "undesirablechange", "jobsecuritypoor", "promotionprospectsadequate",
"salaryadequate", "branch"), class = "data.frame", row.names = c(1L,
2L, 4L, 6L, 10L, 11L, 13L, 15L, 16L, 17L, 19L, 20L, 22L, 23L,
25L, 27L, 29L, 30L, 32L, 33L, 34L, 35L, 39L, 40L, 41L, 42L, 43L,
44L, 45L))
我想用ggplot 2繪製的柱狀圖,具有以下特點:
- 代表同意
陳述在第2欄:6的數據(不同意不繪製)的受訪者的百分比。作爲分支構件(未爲總 受訪百分比) - 巴的
百分比由分支在x軸上 - 問題分組計算百分比(列2:6)被用作「填充」參數
我已經試過玩弄之下,但不能代碼去解決它:
data.r <- melt(rewitemsbr, id.vars='branch')
ggplot(data=data.r, aes(x=value, fill=variable)) +
geom_bar(stat="count", position=position_dodge())
這是我想出來的最好的:
任何幫助非常感謝你。
請您可以添加使用'dput()的一些數據' – Jimbou
我已經這樣做了 - 謝謝你 - 我很新至R所以我學到新的東西 – JRO