Chapter 10 Medal distribution

The Hidden Gems are distributed with Silver Medals ( 43% ) , Gold ( 33% ), Bronze ( 17% ) and No Medals ( 5%)

#2 - Silver
#1 - Gold
#3 - Bronze

Medal <- c(NA,1,2,3)
Medal_Name <- c("NoMedal","Bronze","Silver","Gold")

medal_colors <- c("NoMedal" = fillColor, 
          "Bronze" = fillColor2, 
          "Silver" = fillColor2, 
          "Gold" = fillColor2)

df_Medals <-data.frame(Medal, Medal_Name)


kvcs <- left_join(kvcs,df_Medals)
TotalNoOfRows <- nrow(kvcs)

p1 <- kvcs %>%
  group_by(Medal_Name) %>%
  summarise(Percentage = n()/TotalNoOfRows *100) %>%
  arrange(desc(Percentage)) %>%
  ungroup() %>%
  mutate(Medal_Name = reorder(Medal_Name,Percentage))

 
 
 p1 %>%
  ggplot(aes(x = Medal_Name,y = Percentage, fill = factor(Medal_Name) )) +
  geom_bar(stat='identity',colour="white") +
  scale_fill_manual(values = medal_colors) + 
  geom_text(aes(x = Medal_Name, y = 1, 
                label = paste0("( ",round(Percentage,2)," %)",sep="")),
            hjust=0, vjust=.5, size = 6, colour = 'black',
            fontface = 'bold') +
  labs(x = 'Medal', 
       y = 'Percentage', 
       title = 'Medal and Percentage') +
  coord_flip() + 
  guides(fill=guide_legend(title="Medal Distribution")) +
  theme_fivethirtyeight(base_size = 15)