r - ggplot2中的自定义重新排序直方图填充类别
问题描述
在 ggplot2 中,直方图填充类别按字母顺序排列。我想为我的填充分配一个自定义订单,如下所示:
cust_order <- c("Goal", "Shot on target", "Shot blocked", "Wide shot")
这与此处描述的重新排序颜色不同:How do you order the fill-colours within ggplot2 geom_bar .Code so far...
shot_df %>% filter(Team == "Team A") %>%
ggplot(., aes(x = xG, fill=Type)) +
geom_histogram(binwidth = 0.10)
谢谢!
解决方案
我们可以在客户订单中转换为factor
with然后它应该可以工作levels
vector
shot_df$Type<- factor(shot_df$Type, levels = cust_order)
推荐阅读
- excel - 按日期过滤:今天之前 + 2 天
- flutter - 在 Flutter 中,当使用手机 OTP 登录时,再次收到 OTP 并再次进入重新验证屏幕。我做出改变
- java - 如何在不阻塞当前代码路径的情况下获取ExecutorService的执行结果?
- git - 你能定义文件的哪些部分应该在 git 提交中被视为已更改吗?
- flutter - 如何实现简单的弹出指南,如附图所示
- mongodb - Logstash mutate 删除字段名称'JSON'
- javascript - 将sql数据转换为json文件时如何去掉方括号
- android - 使用 SensorEvent 增加和减少动画和声音
- c++ - 帮助理解复制构造函数
- excel - 如何在粘贴信息和签名后放置正文?