【发布时间】:2020-06-27 23:43:01
【问题描述】:
我正在查看从 11 月到 4 月的数据,并希望绘制从 11 月到 4 月的图。下面是我筛选出感兴趣月份的示例代码。
library(tidyverse)
mydata = data.frame(seq(as.Date("2010-01-01"), to=as.Date("2011-12-31"),by="days"), A = runif(730,10,50))
colnames(mydata) = c("Date", "A")
DF = mydata %>%
mutate(Year = year(Date), Month = month(Date), Day = day(Date)) %>%
filter(Month == 11 | Month == 12 | Month == 01 | Month == 02 | Month == 03 | Month == 04)
我尝试从第 11 个月开始重新排序数据,然后是第 12 个月,然后是 01、02、03 和 04 月份。我使用了代码factor(Month, levels = c(11,12,01,02,03,04)) 和上面的代码,但它不起作用。
我想要一个从十一月开始到四月结束的情节。下面的代码给了我附加的情节
ggplot(data = DF, aes(Month,A))+
geom_bar(stat = "identity")+ facet_wrap(~Year, ncol = 2)
现在,剧情从一月开始一直到十二月——我不想要这个。我想要从 11 月开始的情节,一直到 4 月。我尝试使用 scale_x_date(labels = date_format("%b", date_breaks = "month", name = "Month") 标记情节,但没有成功。任何帮助都会
【问题讨论】:
-
“现在,剧情从一月开始一直到十二月——我不想要这个。我想要从十一月开始的剧情,一直到四月。” i> 但你是
facet_wrappingYear。您认为这会如何影响 11 月至 4 月的订单?
标签: r ggplot2 filter tidyverse axis-labels