r - How can I order the bars in my histogram?
问题描述
I've looked at, for example, "Order Bars in ggplot2 bar graph" and "How to reorder the groups in a grouped bar-chart [duplicate]". But I haven't been able to adapt those to my problem.
I'm trying to make a very basic histogram, with the bars being the number of models in each class and being ordered by that number:
library(ggplot2)
mpg %>%
ggplot +
geom_bar(mapping = aes(
x = reorder(class, count)
))
I can make the unordered version work:
mpg %>%
ggplot +
geom_bar(mapping = aes(
x = class
))
Can anyone help? What am I doing wrong? Is there a way to order that factor by count?
解决方案
推荐阅读
- python - 如何在 Snakemake 中引用 anaconda 环境中的可执行文件
- c++ - 将文件上传到 S3 aws sdk cpp 时出错
- python - 如何为 ECS 任务定义创建日志记录?
- spring - 为什么轴突框架不能插入到自己的表中?
- javascript - 无法读取未定义的属性“id”
- node.js - 用于响应和表达受保护路由的 JSON webtoken 登录授权
- c# - 如何在 C#/.net 中将 XML 数据链接在一起
- python-3.x - 如何识别和计算矩形中的圆?
- github - 在同一个网站(Jekyll GitHub)上创建两个博客而不改变布局/格式
- excel - 如何使用 Excel VBA 单击 Web 复选框?