我想绘制一个按财政年度显示数据的图表。我遇到的问题是ggplot 显示的点在包含信息的数据框中不存在,而不是绘制另一个真正存在的点。请问ggplot的高手能帮帮我吗?非常感谢!!
代码是:
plot = ggplot(data = headcountPerMonth,
aes(x = Month.Number,
y = Headcount,
group = Fiscal.Year,
colour = Fiscal.Year)) +
geom_line() +
geom_point() +
labs(colour = "Fiscal year") +
scale_x_discrete(
name = "Month",
labels = headcountPerMonth$Month.Name
) +
scale_y_continuous(name = "Headcount");
print(plot);
剧情是下一个。如您所见,有一个值 Month = March, Fiscal.Year = 2012,但在 Month = June, Fiscal.Year = 2012 上没有。
图中的数据是下一个。如您所见,没有值 Month = March, Fiscal.Year = 2012 ,但存在于 Month = June, Fiscal.Year = 2012上。
Month Headcount Fiscal.Year Month.Number Month.Name
1 2010-04-01 48 2010 4 abr
2 2010-05-01 49 2010 5 may
3 2010-06-01 52 2010 6 jun
4 2010-07-01 51 2010 7 jul
5 2010-08-01 51 2010 8 ago
6 2010-09-01 51 2010 9 sep
7 2010-10-01 52 2010 10 oct
8 2010-11-01 54 2010 11 nov
9 2010-12-01 54 2010 12 dic
10 2011-01-01 56 2010 1 ene
11 2011-02-01 56 2010 2 feb
12 2011-03-01 61 2010 3 mar
13 2011-04-01 61 2011 4 abr
14 2011-05-01 59 2011 5 may
15 2011-06-01 59 2011 6 jun
16 2011-07-01 61 2011 7 jul
17 2011-08-01 59 2011 8 ago
18 2011-09-01 58 2011 9 sep
19 2011-10-01 59 2011 10 oct
20 2011-11-01 65 2011 11 nov
21 2011-12-01 68 2011 12 dic
22 2012-01-01 72 2011 1 ene
23 2012-02-01 72 2011 2 feb
24 2012-03-01 72 2011 3 mar
25 2012-04-01 77 2012 4 abr
26 2012-05-01 77 2012 5 may
27 2012-06-01 80 2012 6 jun
28 2012-07-01 80 2012 7 jul
29 2012-08-01 77 2012 8 ago
30 2012-09-01 81 2012 9 sep
31 2012-10-01 86 2012 10 oct
32 2012-11-01 86 2012 11 nov
33 2012-12-01 85 2012 12 dic
34 2013-01-01 88 2012 1 ene
35 2013-02-01 86 2012 2 feb
在此先感谢您的帮助。