我试图根据基于月份的销售数据
看到一些趋势Amount
14997.816
26460.718
19607.54
-7612.395
78424.35
4565.6275
5338.02
8650.41
24390.235
9691.5975
168614.2575
887.25
12748.9
7651.5315
402818.9605
1912.45
113.5
11175.6245
23481.0465
10052.49
26962.1625
56399.7825
9751.879
3577.967
25698.45
24844.565
10339.175
165261.7405
460.8935
8383.212
Date
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
6/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
7/1/2010
df <- read.csv("----file path-----")
df$Date <- as.Date( df$Date, '%m/%d/%Y')
require(ggplot2)
ggplot(data = df, aes(Date, Amount)) + geom_line()
我得到的情节与典型的时间序列图不同,是不是因为“金额”中的负值?
如何绘制上述数据的时间序列图?
*销售额是发票+信用票据 ,信用票据是退货产品,它们带有负数
答案 0 :(得分:2)
您没有类似时间序列的图表的原因是您的数据与时间序列不相似。使用基本绘图功能更容易看到,对象中只有两个日期:
plot(Amount ~ Date, data=df)
我很确定这不是故意的。
df
:
structure(list(Amount = c(14997.816, 26460.718, 19607.54, -7612.395,
78424.35, 4565.6275, 5338.02, 8650.41, 24390.235, 9691.5975,
168614.2575, 887.25, 12748.9, 7651.5315, 402818.9605, 1912.45,
113.5, 11175.6245, 23481.0465, 10052.49, 26962.1625, 56399.7825,
9751.879, 3577.967, 25698.45, 24844.565, 10339.175, 165261.7405,
460.8935, 8383.212), Date = structure(c(14761, 14761, 14761,
14761, 14761, 14761, 14761, 14761, 14761, 14761, 14761, 14761,
14761, 14761, 14761, 14761, 14761, 14791, 14791, 14791, 14791,
14791, 14791, 14791, 14791, 14791, 14791, 14791, 14791, 14791
), class = "Date")), .Names = c("Amount", "Date"), row.names = c(NA,
-30L), class = "data.frame")