2017-09-05 26 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