Newbie to R and several hours of searching have driven me insane. I'm working on the Tidy Tuesday project this week and want to display the counts of each runner's nationality that placed first. My research so far has gotten me to display just the number one. I think where I am running into trouble is figuring out how to get my count displayed properly, possibly to not being loaded properly or the filter throwing things off. Then again, might be completely off. Thanks in advance for any assistance!
library(tidyverse) library(ggplot2) library(readr) library(dplyr) ultra_rankings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-26/ultra_rankings.csv') race <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-26/race.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) gt$nationality <- factor(gt$nationality, levels = unique(gt$nationality)) ultra_rankings %>% ggplot(data = gt,mapping = aes(x=nationality, y=n))+ geom_bar(stat = "identity", fill="#000000")+ geom_text(stat = 'count', data = gt, aes(label = after_stat(count), y = after_stat(count), vjust = -25))+ labs( title = "First Place Rankings by Runner Nationality", caption = "Data from runrepeat.com" )+ scale_x_discrete( labels=c("USA", "UK", "France", "Australia", "Spain", "Sweden", "China", "Japan", "Poland", "Hong Kong") )+ theme( plot.title = element_text(hjust = .5))+ ylab("Total First Place Finishes")+ xlab("Runner Nationalities")