r - 如何让 ggplot 从特定月份开始 x 轴
问题描述
我想绘制一个从 11 月开始但延续到下一年的赛季的足球比赛进球数图表。所以我想让 x 轴转到 11 月、12 月、1 月等。
这是我必须使用一些玩具数据的地方
library(tidyverse)
library(lubridate)
df <- data.frame(date = as.Date(c("2017-11-01","2017-11-15",
"2017-12-01","2017-12-15",
"2018-01-01","2018-01-15")),
goals = c(3,2,0,1,3,5))
df %>%
mutate(month=month(date,label = TRUE)) %>%
group_by(month) %>%
summarize(totGoals=sum(goals)) %>%
ggplot(aes(month,totGoals)) +
geom_bar(stat = "identity")
理想情况下,我想使用 purrr 包来解决这个问题,但我无法掌握 fct_reorder 和 fct_relevel。“月”是一个有序因子
TIA
解决方案
推荐阅读
- ios - 单击通用链接时未在 Swift xcode 中提供完整的 URL
- python - 如何将二进制 JP2 (JPEG2000) 字节字符串从缓冲区转换为图像?
- swiftui - 在 SwiftUI 中为 NSViewPepresentable/UIViewRepresentable 添加一个偏好键
- python - tkinter:如何避免此“ValueError:无法将字符串转换为浮点数:”?
- c++ - 是否可以鼓励线程排队而不强迫它?
- python - 浮点数排序列表
- amazon-web-services - 如何将导出的 Google AutoML 机器作为 API 发布?
- python-turtle - Python海龟绘制后,在绘图内点击鼠标,清屏重绘
- javascript - 写 for 循环更短
- r - Ggraph 似乎无法显示图例