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
<- c(NA,1,2,3)
Medal <- c("NoMedal","Bronze","Silver","Gold")
Medal_Name
<- c("NoMedal" = fillColor,
medal_colors "Bronze" = fillColor2,
"Silver" = fillColor2,
"Gold" = fillColor2)
<-data.frame(Medal, Medal_Name)
df_Medals
<- left_join(kvcs,df_Medals)
kvcs <- nrow(kvcs)
TotalNoOfRows
<- kvcs %>%
p1 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)