── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Q1
What are the top 10 National Sports Associations with the most subvention granted over the past 5 years?
# making a new data of the average subvention received over the past 5 years, and then taking the top 10 out. top10 <- df_clean |>group_by(engname) |>summarise(avg_subsidy =mean(subsidy2)) |>arrange(-avg_subsidy) |>top_n(10, avg_subsidy)
# making the bar chart and text on the bars for it to be easier to read. p1 <-ggplot(top10, aes(x =reorder(engname, avg_subsidy), y = avg_subsidy,fill =reorder(engname, -avg_subsidy) )) +geom_col(stat ="engname",width =0.8,alpha =0.8) +geom_text(aes(label = engname,y = avg_subsidy*0.5,hjust =0.5),color ="black",size =2.3) +labs(title ="Top 10 NSAs by Average Subvention", x ="Average Subsidy (HKD)",y ="National Sports Associations",caption ="Source: data.gov.hk | Author Joshua Kwok") +scale_y_continuous(labels = scales::comma) +theme_minimal() +theme(legend.position ="none",axis.text.y =element_blank(),axis.ticks.y =element_blank(),plot.margin =margin(1, 2, 1, 1, "cm") ) +coord_flip()
What is the overall trend of subvention granted to all NSAs?
# making new df for total subvention granted and percentage change of subvention grantedyearly_total <- df_clean |>group_by(year) |>summarise(total_subsidy_all =sum(subsidy2)) yearly_growth <- yearly_total |>mutate(growth_rate = (total_subsidy_all -lag(total_subsidy_all)) /lag(total_subsidy_all) ) glimpse(yearly_growth)
How has winning medals affected the subvention granted to according NSAs.
# defining the olympic sports associations and NSAs that won medals in international level competitions. winning_sports <-c("Hong Kong Fencing Association","Hong Kong China Swimming Association","The Cycling Association of Hong Kong, China Limited","The Hong Kong Table Tennis Association Limited","Hong Kong Rugby Union","Hong Kong Squash")olympic_sports <-c("Hong Kong Archery Association","The Gymnastics Association of Hong Kong, China","Hong Kong Association of Athletics Affiliates Limited","Hong Kong Badminton Association Limited", "Hong Kong Basketball Association Limited","Volleyball Association of Hong Kong, China Limited","Hong Kong Boxing Association Limited","The Hong Kong Canoe Union Limited", "Hong Kong Equestrian Federation","The Hong Kong Football Association Limited","Hong Kong Golf Association Limited", "Handball Association of Hong Kong, China Limited","The Hong Kong Hockey Association", "The Judo Association of Hong Kong, China","Hong Kong, China Rowing Association", "Hong Kong Sailing Federation", "Hong Kong Shooting Association", "China Hong Kong Mountaineering and Climbing Union Limited","Hong Kong Taekwondo Association Limited", "The Hong Kong Tennis Association Limited", "Hong Kong Triathlon Association Limited")
# Creating the graphs for the medal winning NSAs, with facetp4 <- df_clean |>filter(engname %in% winning_sports) |>ggplot(aes(x = year, y = subsidy2/1000000,color = engname), ) +labs(x =NULL, y ="Subsidy in Million HKD",title ="Winning Sports Subsidies (2017-2021)",color ="NSAs",) +geom_line(size =0.5,alpha =0.7) +geom_point(size =0.5,alpha =0.7) +theme_bw() +theme(legend.position ="none",strip.text =element_text(size =6.5), panel.spacing =unit(0.5, "lines")) +facet_wrap(~engname)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ggplotly(p4)
ggsave("out/winning_sports.jpg", width =8, height =6, units ="in")
Q5
Has the subvention granted to NSAs been affected by appearance in Olympics?