这是我的数据栏
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)
尝试:
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)
我在fill
中添加了aes
,然后也更改了scale_fill_manual
。
输出: