2017-09-05 64 views
1

這裏是我的數據R將不會讓我改變單個條的顏色上ggplot無論什麼

structure(list(summresolution = c("New supplier Found", "Supplier educated about DMEPOS\n", 
            "Unresolved", "Supplier educated about DMEPOS\n", 
            "Resolved by current supplier", 
            "Supplier educated about inquiry\n"))) 

我使用這個代碼創建一個ggplot列:

sumrc<-ggplot(subset(longdata,!is.na(summresolution)), 
       aes(x=summresolution)) 

sumrcbycount <- sumrc + 
    geom_bar(stat = "count") + 
    coord_flip()+ 
    scale_fill_manual("legend", 
        values = c("New supplier Found" = "black", 
           "Beneficiary Educated" = "orange", 
           "Resolved by current supplier" = "blue", 
           "Unresolved"= "red")) 

print(sumrcbycount) 

我已經在網上搜尋了答案,因爲它看起來像一個簡單的問題,但不管我做什麼,顏色都是黑色的。

+0

你的榜樣不起作用。清理你的工作空間並嘗試自己。 –

+0

你是什麼意思?所有酒吧會有一種顏色還是每個酒吧有不同的顏色? – LyzandeR

+0

好的我在這裏有一個非常大的數據集,我只是試圖顯示1列數據我建立我的圖表。我是R的新手,也是Stack的新手,所以我不太擅長提供像你所想的那樣的示例數據。創建圖表的代碼是100%正確的,因爲它可以在我的控制檯中工作。爲什麼不改變顏色壽? –

回答

0

嘗試:

library(ggplot2) 
sumrc<-ggplot(subset(longdata,!is.na(summresolution)), 
       aes(x=summresolution, fill=summresolution)) 
sumrcbycount <- sumrc + 
    geom_bar(stat = "count") + 
    coord_flip() + 
    scale_fill_manual("legend", values = c("Supplier educated about inquiry\n" = "black", 
             "Supplier educated about DMEPOS\n" = "orange", 
             "Resolved by current supplier" = "blue", 
             "New supplier Found" = "yellow") 
        ) 
print(sumrcbycount) 

我在你aes添加fill再變scale_fill_manual了。

日期:

enter image description here