尝试生成与excel相同的条形图,但是在R中可以吗?想要按用户显示每周的订单总数,以及每周的开始和结束日期。
User Due_date Status
a 02-10-2017 Complete
b 02-02-2017 Ordered
a 02-08-2017 Complete
c 02-08-2017 Complete
a 02-08-2017 Ordered
s 02-06-2017 Complete
c 02-06-2017 Complete
s 02-06-2017 Ordered
b 02-06-2017 Ordered
c 02-11-2017 Complete
a 02-11-2017 Ordered
s 02-11-2017 Ordered
c 02-01-2017 Complete
s 02-01-2017 Ordered
b 02-01-2017 Complete
b 02-10-2017 Complete
尝试生成报告,但未显示在excel中的显示范围,请检查代码和所附的屏幕截图。
library(lubridate)
Data$Week_Due = (ceiling_date(Data$Due.Date, "week") + ifelse(weekdays(Data$Due.Date) %in% c("Saturday", "Sunday"), 5,-2))
library(rpivotTable)
rpivotTable(Data, aggregatorName = "Count", rows = "User", cols = c("Week_Due","User","Status"), width = "100%", height = "500px",rendererName = "Bar Chart")
确定-这是一个更精致的示例,应该更接近于您要实现的示例:要在x轴上修改标签以显示日期范围,您需要将其放入一个简单的函数中。而且,我改用breaks
代替date_breaks
,以便在直方图的条形图下方的中间或多或少地移动刻度线。
ggplot(Data, aes(x = Due_date)) + geom_histogram(binwidth = 7) +
scale_x_date(breaks = seq(min(Data$Due_date), max(Data$Due_date), by = 7),
labels = function(x) paste0(format(x, "%d-%m-%Y"), ", ", format(x+7, "%d-%m-%Y"))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))