日付ごとの生産性測定値を含むデータフレームがあります。日付は 2013 年 5 月 4 日から 2014 年 7 月 11 日までです。生産性指標は 6 組織単位です
データは次のようになります。
> str(prods)
'data.frame': 588 obs. of 6 variables:
$ SOM : Factor w/ 7 levels "BVG1 Scotland",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Skill: Factor w/ 1 level "A": 1 1 1 1 1 1 1 1 1 1 ...
$ Date : Date, format: "2013-04-05" "2013-04-12" "2013-04-19" "2013-04-26" ...
$ Prod : num 2.97 2.94 2.87 2.95 2.97 2.97 2.97 2.94 2.86 2.98 ...
$ Month: num 4 4 4 4 5 5 5 5 5 6 ...
$ Year : num 2013 2013 2013 2013 2013 ...
概要:
> summary(prods)
SOM Skill Date Prod Month Year
BVG1 Scotland :84 A:588 Min. :2013-04-05 Min. :2.370 Min. : 1.00 Min. :2013
BVG11 Highlands & IslandsA :84 1st Qu.:2013-08-28 1st Qu.:2.888 1st Qu.: 4.75 1st Qu.:2013
BVG12 North East ScotlandA :84 Median :2014-01-20 Median :3.030 Median : 7.00 Median :2014
BVG13 Central ScotlandA :84 Mean :2014-01-20 Mean :3.029 Mean : 6.75 Mean :2014
BVG14 South East ScotlandA :84 3rd Qu.:2014-06-14 3rd Qu.:3.180 3rd Qu.: 9.00 3rd Qu.:2014
BVG15 West Central ScotlandA:84 Max. :2014-11-07 Max. :3.510 Max. :12.00 Max. :2014
BVG16 South West ScotlandA :84
"Prod"
以下に示すように、現在までの実際の製品を描画できる
2013年と2014年を示すggplot2を使用して線グラフを描画したいだけです。
私が使用したコードは次のとおりです。
ggplot(prods, aes(x = Date, y = Prod, group = SOM)) +
geom_line(lwd = 1.3, colour = "red") +
ylab("Actual Productivity") + theme(axis.title.x=element_blank()) +
facet_wrap(~ SOM)
たとえば、2013 年ラインは紫、2014 年ラインは赤など、年ごとに prod を表示するとよいでしょう。
どんな助けでも大歓迎です。
よろしく、
これは私がしたことです:
ggplot(prods[Year==2013,], aes(x = Date, y = Prod, group = SOM)) +
geom_line(lwd = 1.3, colour = "purple") +
ylab("Actual Productivity") + theme(axis.title.x=element_blank()) +
geom_line(data=prods[Year==2014,], aes(x = Date, y = Prod, group = SOM),lwd = 1.3, colour = "red") +
scale_color_manual("Period", values = c("purple","red"), labels = c("2013","2014")) +
facet_wrap(~ SOM)
エラーは発生していませんが、画像にポップアップする凡例はありません。次のようになります。