我希望使用stat_smooth生成一条3-7行的线图,以产生平滑的曲线,而不是在每个数据点处产生变化的曲线。
这是我目前剧情的剧本:
Data_Arr %>%
ggplot(aes(x=Period, y=M_Min, colour = Day_Week)) +
geom_line(aes(group=`Day Name`)) +
geom_hline(aes(yintercept= 120, linetype = "120MPM"), colour= 'lawngreen')+
ylim(0,200)+
stat_smooth(aes(x=Period, y=M_Min, colour = Day_Week))+
theme_readable()
Stat_smooth似乎适用于其中一些但不是全部?我之前没有使用过stat_smooth所以这可能是一个我错过的简单修复
这是数据集
Data_Arr = structure(list(Season = c(1718, 1718, 1718, 1718, 1718, 1718,
1718, 1718, 1718, 1718), Week = c("Wk 40 Newcastle_H", "Wk 40 Newcastle_H",
"Wk 40 Newcastle_H", "Wk 41 Wasps_A", "Wk 41 Wasps_A", "Wk 41 Wasps_A",
"Wk 42 No_Game", "Wk 40 Newcastle_H", "Wk 40 Newcastle_H", "Wk 40
Newcastle_H"
), Day_Week = c("Wk 40 Newcastle_H Attack_3G", "Wk 40 Newcastle_H
Defence_3G",
"Wk 40 Newcastle_H Newcastle_H", "Wk 41 Wasps_A Defence_3G",
"Wk 41 Wasps_A Attack_3G", "Wk 41 Wasps_A Wasps_A", "Wk 42 No_Game
Rugby_Games",
"Wk 40 Newcastle_H Attack_3G", "Wk 40 Newcastle_H Defence_3G",
"Wk 40 Newcastle_H Newcastle_H"), Date = structure(c(1522886400,
1522713600, 1523059200, 1523318400, 1523491200, 1523664000, 1523923200,
1522886400, 1522713600, 1523059200), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), Day = c("Thu", "Tue", "Sat", "Tue", "Thu",
"Sat", "Tue", "Thu", "Tue", "Sat"), `Training/Match` = c("Training",
"Training", "Match_P", "Training", "Training", "Match_P", "Training",
"Training", "Training", "Match_P"), `Day Name` = c("Attack_3G",
"Defence_3G", "Newcastle_H", "Defence_3G", "Attack_3G", "Wasps_A",
"Rugby_Games", "Attack_3G", "Defence_3G", "Newcastle_H"), `Full
Match/Training/Quarters` = c("Training",
"Training", "Match_P", "Training", "Training", "Match_P", "Training",
"Training", "Training", "Match_P"), `Squad Classification` = c("Senior",
"Senior", "Senior", "Senior", "Senior", "Senior", "Senior", "Senior",
"Senior", "Senior"), `Forward/Back` = c("Backs", "Backs", "Backs",
"Backs", "Backs", "Backs", "Backs", "Backs", "Backs", "Backs"
), Position = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L), .Label = c("Prop", "Hooker", "Second Row", "Back Row", "Scrum Half",
"Fly Half", "Centre", "Wing/FullBack"), class = "factor"), Player.Name =
c("Arr Jonny",
"Arr Jonny", "Arr Jonny", "Arr Jonny", "Arr Jonny", "Arr Jonny",
"Arr Jonny", "Arr Jonny", "Arr Jonny", "Arr Jonny"), Period = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("Min_1", "Min_2",
"Min_3", "Min_4", "Min_5", "Min_6", "Min_7", "Min_8", "Min_9",
"Min_10"), class = "factor"), M_Min = c(154.3, 188, 156.2687833,
175.9911, 159.422783333333, 137.872366666667, 153.349133333333,
150.6, 166, 139.1597833)), .Names = c("Season", "Week", "Day_Week",
"Date", "Day", "Training/Match", "Day Name", "Full Match/Training/Quarters",
"Squad Classification", "Forward/Back", "Position", "Player.Name",
"Period", "M_Min"), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
由于
编辑:这是我想要制作的剧情类型,但这个是以excel制作的,我希望在R中制作。
答案 0 :(得分:0)
基于您的问题,这是我的主张:基于Period和Day_week的分组数据,并产生平均M_min。然后使用ggplot geom_line()绘图:
Data_Arr %>%
group_by(Period,Day_Week) %>%
summarise(mean_M_Min=mean(M_Min)) %>%
ggplot(aes(x=Period,y=mean_M_Min,colour=Day_Week,group=Day_Week)) +
geom_line()