以下是我的数据集
feature_user <- data.frame (Features = c("Battery","Build_Design", "Camera","Connectivity","Delivery",
"Design", "Display", "Gaming_Experience", "Performance",
"Post_Usage", "Protection", "Recommendation", "Sound", "Value_Money"),
Users = c(852, 89, 471, 96, 228, 143, 131, 18, 379, 354, 35, 271, 99, 510))
我正在尝试使用以下代码绘制数据
library(ggplot2)
ggplot(feature_user, aes(x = reorder(Features, Users), y = Users)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_brewer(palette = "Set1") +
coord_flip() +
ggtitle("Most Talked Feature by Users") +
ylab("No of Users") +
xlab("Features")
但问题是,我没有按照scale_fill_brewer中提到的颜色代码获得输出。相反,我得到了简单的灰色条形图。我不确定是什么问题。请帮助
你需要在你的fill
的aes
中添加geom
library(ggplot2)
ggplot(feature_user,aes(x=reorder(Features,Users),y=Users)) +
geom_col(stat='identity', aes(fill=Features), width=.5)+
coord_flip() +
ggtitle("Most Talked Feature by Users") +ylab("No of Users") + xlab("Features")
结果是
但是,通过添加:
scale_fill_brewer(palette = "Set1") +
它与结果混淆了。并且某些列不存在。