【发布时间】:2020-08-31 21:18:01
【问题描述】:
我真的在用 ggplot 和 dplyr 处理 R 中的情节。
我有一个带有列的数据框:
Customer.Name, Customer.Code, Product, Date, Platform, Input.Records, Output.Records
我使用 dplyr 进行了分组,按日期对输入记录进行分组。
df$Date <- as.Date(df$Date, format = "%Y-%m-%d")
dateGrouping <- df%>% group_by(`Date`) %>% summarise(`Input.Records` = sum(`Input.Records`))
然后我尝试绘制它。
myPlot <- ggplot(data=dateGrouping, aes(x=factor(Date), y=`Input.Records`, group=1)) +
geom_line() + ylim(0, 85000000)
myPlot
所以我把geom_line() 换成了geom_path()
而且这看起来肯定是错误的......为什么路径来回走动?应该是从左到右的直线轨迹吧?
这是复制示例的代码。仅包含分组帧的代码,因为完整文件太大且包含机密数据。
library(ggplot2)
library(dplyr)
df <- data.frame("Date" = c( "2020-08-10", "2020-08-11", "2020-08-12", "2020-08-13", "2020-08-14", "2020-08-15", "2020-08-16", "2020-08-17", "2020-08-18",
"2020-08-19", "2020-08-20", "2020-08-21", "2020-08-22", "2020-08-23", "2020-08-24"),
"Input.Records" = c(19501675,19298520,75546425,90104271,34139598,35384083,11849216,21996019,241643844,55643434,20733736,46198249,9815057,78211864,103263783))
myPlot <- ggplot(data=df, aes(x=factor(Date), y=`Input.Records`, group=1)) +
geom_path() + ylim(0, 85000000)
myPlot
【问题讨论】:
标签: r dataframe ggplot2 plot dplyr