我有一个包含以下格式数据的数据框。
Category_Name, State, Percent
B , Accepted, 20
B , Declined, 80
A , Accepted, 10
B , Declined, 90
我希望它绘制它,使得类别名称的顺序取决于从最大到最小接受状态的百分比。
到目前为止我已经
了jr.states$category_name <- factor(jr.states$category_name, levels = sort(levels(jr.states$percent[state == "accepted"])))
jr.states %>%
ggplot(aes(x=category_name, y = percent * 100, fill = factor(state)), order=-percent) +
geom_bar(stat = "identity") +
coord_flip() +
labs(x ="Category", y ="Percent", title = "Accept/Decline/Ignore Rates by Category")
但我收到了错误
Error in levels(jr.states$percent[state == "accepted"]) :
object 'state' not found
非常感谢任何帮助