[英]R data not being plotted correctly
I'm really struggling with plots in R with ggplot and dplyr.我真的在用 ggplot 和 dplyr 处理 R 中的图。
I have a dataframe with columns:我有一个带列的数据框:
Customer.Name, Customer.Code, Product, Date, Platform, Input.Records, Output.Records
I performed a grouping with dplyr, to group the input records by the date.我使用 dplyr 进行了分组,以按日期对输入记录进行分组。
df$Date <- as.Date(df$Date, format = "%Y-%m-%d")
dateGrouping <- df%>% group_by(`Date`) %>% summarise(`Input.Records` = sum(`Input.Records`))
Then I tried to plot that.然后我试图绘制它。
myPlot <- ggplot(data=dateGrouping, aes(x=factor(Date), y=`Input.Records`, group=1)) +
geom_line() + ylim(0, 85000000)
myPlot
But the output looks wrong, it looks like a bar plot, there is no connection between the lines但是输出看起来不对,看起来像条形图,线条之间没有联系
So I swapped geom_line()
with geom_path()
所以我换
geom_line()
与geom_path()
And this definitely looks wrong...why is the path going back and forth?这看起来肯定是错误的......为什么这条路来回走动? it should be a left-to-right linear trajectory shouldn't it?
它应该是一个从左到右的线性轨迹,不是吗?
This is the code to replicate the example.这是复制示例的代码。 Including only the code for the grouped frame because the full file is too large and contains confidential data.
仅包含分组帧的代码,因为整个文件太大且包含机密数据。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.