r - ggplot2:组内的条形图顺序
问题描述
我有我想制作条形图的样本数据。数据将在组内组内显示。
样本数据框如下:
sample<-data.frame("Flag"=c(TRUE,TRUE,TRUE,TRUE,TRUE,FALSE),
"type"=c("Best","Normal","Dormant","Lost","Cheap","Normal"),
"n" =c(9859,5008,3807,1747,1085,992))
我想在列的Flag
order by内制作条形图。N
type
这是制作情节:
make_plot <-ggplot2::ggplot( sample, aes(fill=reorder(type,n), x=Flag, y=n)) +
geom_bar(position="dodge", stat="identity")
make_plot
我不明白如何使用带因子的重新排序。或重新排序的因素
sample$type <-factor(sample$type,
levels=c("Best","Normal","Dormant","Lost","Cheap","Normal"))
它会给出错误,因为级别中有重复项。
我该如何解决这个问题?
解决方案
推荐阅读
- java - 如何将参数传递给java lambda
- shopify - 当 Shopify 商店客户登录到他在商店中的帐户时,我还想让他登录到我的 Shopify 应用程序
- php - 使用 XmlReader 读取 XML 文件时从 XML 文件中删除节点?
- azure - 使用 Azure CLI 列出 Azure Monitor 中的所有警报规则
- java - 读取文本文件并将内容添加到 ArrayList
- node.js - 通过 Fiddler 发送 NodeJs Axios 请求
- python - 如何在下载请求 Python 时播放音频文件
- postgresql-9.2 - Postgres - 查找重复并将其中一行更新为零
- d3.js - D3.js 从 csv 创建嵌套数组
- c - 链接中的重定位条目(C 编程)