-1
爲什麼不是閃避參數爲每個組創建多個酒吧?我正在尋找一個分組的酒吧情節,而不是我得到的那個。ggplot閃避不分組酒吧
df<-data.frame(c(40,23,18,41,15,14,38,21,1),c(rep("Do you agree with \nthe 'Hands Up' protestors ?",3),rep("Have the Police alienated themselves\n from the Public?",3),rep("Are the public ignoring the\n dangers Police face everyday?",3)),c("49%","28%","22%","59%","21%","20%","63%","35%","2%"),c(1,1,1,2,2,2,3,3,3))
colnames(df)<-c("values","names","percentages","group")
ggplot(df,aes(names,values,group=group))+
geom_bar(stat = "identity",position = "dodge",fill=rep(c("green","red","orange"),3))+
geom_text(aes(label=percentages))+
ylab("number of votes")+
xlab("")+
ggtitle("Police Opinion polls")
我的結果:
我想要什麼:
我測試了你的代碼,位沒有得到我正在尋找的分組條形圖。我用一個例子更新了我的代碼,如果我的請求不清楚,我很抱歉 – Rilcon42
我使用了您發佈的示例數據,在我的答案中添加了代碼並獲得了一個閃避的條形圖。你能解釋一下,你通過運行示例數據得到的結果是什麼,這樣我就可以確定哪裏出錯了? – Marius
我的壞 - 我沒有注意到我們正在使用兩個不同的列df $響應。當你使用'response'時,我將它從'group'變量中取出 – Rilcon42