skip to Main Content
The smarter way
to do assignments.

Please note that this is just a preview of a school assignment posted on our website by one of our clients. If you need assistance with this question too, please click on the Order button at the bottom of the page to get started.

In this question, we want to compare average `Maximum Velocity`, average `Meterage Per Minute`, and average `Player Load Per Minute` by **player** between the training data and match data using a bar graph.As a general outline, we will 1. For both the match and train data i. Select the appropriate columns ii. Rename the column names for easier use later iii. Group by players iv. Summarize the data by player v. Change from wide to long format 2. Join the two data sets using `left_join()` function 3. Change the joined data from wide to long 4. Plot Below, a couple of new functions are used. – `rename_all()`: which renames columns based on rules that are supplied to the function, and we rename columns using the call/rule `~str_replace_all(., ” “, “_”)`. Inside the `str_replace_all()` function, the first argument, `.`, means all columns (or more generally, the `.` operator means all variables), the second argument `” “` means look for any spaces in the string, and the third argument, `”_”`, means replace all spaces with an underscore. – `ungroup()`: undoes a `group_by()`. We use this because we want to continue manipulating the data frame, and we need to remove any grouping arguments so as not to impose the grouping on our future manipulations. – `full_join()`: as the name suggests, this function will join two data sets based on like columns (e.g., `Player_Name` or `Position`). The key here is that both data sets **have** to have the same column names and identifying factors. There are other `join()` functions that would also work, I recommend looking into the `join()` functions as they are very useful.As with the previous lab, you will need to fill in certain parts of the code.What you need to supply will be marked by a `#### FILL IN` after the code.#### Answer“`{r}# subset the match data and manipulatematch_sub <-match %>% #### FILL IN select(“Maximum Velocity”,”Meterage Per Minute”, “Player Load Per Minute”, “Player Name”) %>% #### FILL IN rename_all( ~str_replace_all(., ” “, “_”) ) %>% group_by(Player_Name) %>% #### FILL IN summarise_at(var(Maximum_Velocity, Meterage_Per_Minute, Player_Load_Per_Minute), mean) %>% #### FILL IN ungroup() %>% pivot_longer(-Player_Name, names_to = “Metric”, values_to = “Game”)# subset the training data and manipulatetrain_sub <-train %>% #### FILL IN select(“Maximum Velocity”,”Meterage Per Minute”, “Player Load Per Minute”, “Player Name”) %>% #### FILL IN rename_all( ~str_replace_all(., ” “, “_”) ) %>% group_by(Player_Name) %>% #### FILL IN summarise_at(var(Maximum_Velocity, Meterage_Per_Minute, Player_Load_Per_Minute), mean) %>% #### FILL IN ungroup() %>% pivot_longer(-Player_Name, names_to = “Metric”, values_to = “Training”)joined_df = match_sub %>% # start with one of the data sets, doesn’t matter which in this case full_join(train_sub, by = c(‘Player_Name’, ‘Metric’)) %>% # join with the other, using player_name and metric as the joining columns pivot_longer(-c(Player_Name, Metric), names_to = “Session”, values_to = “Values”) # pivot so that we have long formatggplot(joined_df, aes(x =Player_Name , y =Value, fill =Session , width = 0.75)) + #### FILL IN geom_bar(position = ‘dodge’, stat = ‘identity’) + # this creates our bar plot, position says put the different fills next to each other, stat says map it as the same as the original source (i.e., y value) facet_wrap(~ Metric, # this creates an individual plot for each metric labeller = labeller(Metric = c(“Maximum_Velocity” = “Maximum Velocity”, # makes the labels nicer “Meterage_Per_Minute” = “Meterage Per Minute”, “Player_Load_Per_Minute” = “Player Load Per Minute”))) + theme(legend.position=”bottom”, # formatting for the legend, puts the legend below the plot, and removes the title legend.title=element_blank()) + xlab(‘Player Name’)“`## Question 2In this question, we want to compare `Maximum Velocity`, `Meterage Per Minute`, and `Player Load Per Minute` by **position** between the training data and match data without summarizing the data.Here, we will use a violin plot, overlaying the raw data points, to get an understanding for the **distribution** of the data.As a general outline, we will 1. For both the match and train data i. Select the appropriate columns ii. Rename the column names for easier use later v. Change from wide to long format 2. Join the two data sets using `left_join()` function 3. Change the joined data from wide to long 4. Make sure that all players who play the same position have the same position **string** 5. Plot Below, two key functions are used to manipulate strings. – `str_extract()`: extracts the chosen pattern from the supplied string. Below, we search for the patter `c(“Midfielder|Defender|Back|Stikder|Goal Keeper|Wing|Striker”)` over the `Position_Name` string. This means if the an element `Position_Name` **contains** the word “Midfielder” or “Defender” or … or “Striker”, return **only** “Midfielder” or “Defender” or … or “Striker”. This means that if we have the position “Central Defensive Midfielder”, this gets changed to “Midfielder”, and so on. – `str_replace_all()`: replaces a pattern in the supplied string with the chosen replacement. Below, we say `str_replace_all(“Back”, “Defender”)`, which searches over a string (i.e., `Position_Name`) and changes any instance of “Back” to “Defender”.As with the previous lab, you will need to fill in certain parts of the code.What you need to supply will be marked by a `#### FILL IN` after the code.#### Answer“`{r}# subset the match data and manipulatematch_sub_2 <-match %>% #### FILL IN select(“Maximum Velocity”, “Meterage Per Minute”, “Player Load Per Minute”, “Player Name”) %>% #### FILL IN rename_all(“Maximum Velocity”, 1, “Meterage Per Minute”,2, “Player Load Per Minute”,3) %>% #### FILL IN pivot_longer(-Position_Name, names_to = “Metric”, values_to = “Game”)# subset the train data and manipulatetrain_sub_2 <-train %>% #### FILL IN select(“Maximum Velocity”, “Meterage Per Minute”, “Player Load Per Minute”, “Player Name”) %>% #### FILL IN rename_all() %>% #### FILL IN pivot_longer(-Position_Name, names_to = “Metric”, values_to = “Training”)joined_df_2 = match_sub_2%>% #### FILL IN full_join(train_sub_2) %>% #### FILL IN pivot_longer(-c(Position_Name, Metric), names_to = “Session”, values_to = “Values”) %>% mutate(Position_Name = Position_Name %>% str_extract(c(“Midfielder|Defender|Back|Stikder|Goal Keeper|Wing|Striker”)) %>% str_replace_all(“Back”, “Defender”))ggplot(joined_df_2, aes(y = Position_Name , x = Value , fill =Session, width = 0.75)) + #### FILL IN geom_violin(alpha = 0.80, scale = “width”, trim = FALSE, draw_quantiles = c(0.25, 0.5, 0.75)) + # explore what each of the variables does geom_point(size = 2, shape = 21, position = position_jitterdodge(0.1)) + # explore what each of the variables does facet_wrap(~ Metric, # make a different plot for each metric scales = “free_x”, # make it so the x axis scales are different for each metric labeller = labeller(Metric = c(“Maximum_Velocity” = “Maximum Velocity (Units)”, # renames the title of each plot to something nicer “Meterage_Per_Minute” = “Meterage Per Minute”, “Player_Load_Per_Minute” = “Player Load Per Minute”))) + ylab(‘Position’) + xlab(‘Value’) + theme(legend.position=”bottom”, # puts the legend at the bottom legend.title=element_blank(), # no title for the legend axis.text.y = element_text(angle = 45, vjust = 0.5, size = 10)) # rotates the text by 45 degrees“`## Question 3Questions 1 and 2 take different approaches to visualizing the same data. The main differences between the two are the scales at which they present the information and how “cleanly” the data is presented.What are some advantages and disadvantages to each of the two approaches of visualizing the data?Which final data set, `joined_df` or `joined_df_2`, would be more suitable for statistical analysis?What would be the impact of having multiple games and training sessions worth of data, instead of one each.Discuss.#### Answer

GET HELP WITH THIS ASSIGNMENT TODAY

Clicking on this button will take you to our custom assignment page. Here you can fill out all the additional details for this particular paper (grading rubric, academic style, number of sources etc), after which your paper will get assigned to a course-specific writer. If you have any issues/concerns, please don’t hesitate to contact our live support team or email us right away.

How It Works        |        About Us       |       Contact Us

© 2018 | Intelli Essays Homework Service®