Hi @KyleWhoIsTall ,
The count of runners per nationality is already in the n column of your tibble, so the geom_text line is easier.
I spotted a few additional things:
- You hard-coded the full name of countries in the x scale, which you shouldn’t do as it is not replicable and prone to error (and indeed you wrote Hong Kong that doesn’t show in the country abbreviations). So I created a “countries” tibble that matches each abbreviation with full country names. Feel free to expand the list to all other countries.
- I also deleted the line where you transform nationality into a vector, it is quicker to change this in aes part with fct_reorder.
Hope it helps
ultra_rankings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-26/ultra_rankings.csv')
gt <- ultra_rankings %>% #New data frame with all the data controls
filter(rank==1) %>% #Only results in showing rows with first place finishes
group_by(nationality) %>%
count(nationality) %>%
arrange(-n) %>%
head(10)
#create reference tibble with
countries_abr <- c("USA", "GBR", "FRA", "AUS", "ESP", "SWE", "CHN", "CAN", "JPN", "POL")
countries_full <- c("USA", "UK", "France", "Australia", "Spain", "Sweden", "China", "Canada", "Japan", "Poland")
countries <- tibble(countries_full, countries_abr)
#plot
gt %>% left_join(countries, by = c("nationality" = "countries_abr")) %>%
ggplot(aes(x=fct_reorder(countries_full, desc(n)), y=n))+
geom_bar(stat = "identity", fill="#000000")+
geom_text(aes(label = n), vjust = -0.5, size = 3) +
labs(
title = "First Place Rankings by Runner Nationality",
caption = "Data from runrepeat.com",
y = "Total First Place Finishes",
x = "Runner Nationalities"
)