library(tidyverse)
library(kableExtra)
rugby <- read_csv("Rugby_League_2016_17.csv")My Brief Guide to Quarto
1 Introduction
This is a test in running Code, Showing and Hiding it, Rendering, Saving as HTML in Folder and Publishing with Link.
First a single working directory was set up to identify where all the data and other files must be located. Otherwise data will not be uploaded and message was re-occurring stating that not in Working Directory.
The packages to be used (eg. tidyverse and kable) were loaded. The dataframe “Rugby League 2016 2017” was loaded and a new dataframe ‘rugby’ was formed. The message and warning = F to ensure that messages were not published in the HTML. The full code was shown for one graph and hidden for another using echo = false.
You can add a new chunk by clicking the Insert Chunk button on the toolbar (the green box with the c)
team_home_away_Year_17 <- rugby %>%
group_by(Home_Team, Year) %>%
summarise(Home_Score = sum(unique(Home_Score), na.rm = TRUE),
Away_Score = sum(unique(Away_Score), na.rm = TRUE)) %>%
pivot_wider(names_from = Year, values_from = c(Home_Score, Away_Score)) %>%
mutate(Total_Score_2017 = Home_Score_2017 + Away_Score_2017) %>%
arrange(desc(Home_Score_2017)) %>% # Filter the dataframe to include only Home_Score_2017 and Away_Score_2017
select(Home_Team, Home_Score_2017, Away_Score_2017) # Create a Score_Type column
ordered_teams <- c("Castleford Tigers", "Catalans Dragons", "Huddersfield Giants", "Hull FC", "Leeds Rhinos", "Salford Red Devils", "St Helens", "Wakefield Trinity", "Warrington Wolves", "Widnes Vikings", "Wigan Warriors")# Filter the data for the year 2017
team_home_away_2017 <- team_home_away_Year_17 %>%
select(Home_Team, Home_Score_2017, Away_Score_2017) %>%
filter(!is.na(Home_Score_2017) & !is.na(Away_Score_2017)) # Reshape the data for plotting
team_home_away_long <- team_home_away_2017 %>%
pivot_longer(cols = c(Home_Score_2017, Away_Score_2017), names_to = "Score_Type", values_to = "Score")
ggplot(team_home_away_long, aes(x = Home_Team, y = Score, fill = Score_Type)) +
geom_bar(stat = "identity", position = position_dodge(width = -0.9)) + # Adjust position here +
labs(title = "Home and Away Scores in 2017",
x = "Team",
y = "Score",
fill = "") +
scale_fill_manual(values = c("red","blue"), labels = c("Away Score", "Home Score")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, face = "bold", size = 10),
legend.position = "top",
plot.title = element_text(hjust = 0.5), # Centering the plot title
panel.grid.major = element_blank(), # Removing major gridlines
panel.grid.minor = element_blank()) + # Removing minor gridlines
guides(fill = guide_legend(reverse = TRUE)) + # Reorder legend
scale_x_discrete(limits = ordered_teams)More commentary will be added. The HTML will include the code.
To provide an example of output without code {r, message = F, warning = F, echo = FALSE} the Stacked barchart for the 2018 Home and Away scores per Team are presented below.
Render button in the toolbar (the blue arrow) was clicked to generate the HTML file.
It opened automatically in the Browser and was saved to the same folder as this Quarto file namely “RCode for Charts”.