Professional Documents
Culture Documents
knit
summer=read.csv('../input/summer.csv')
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
:::
head(summer)
str(summer)
A data.frame: 6 × 9
1 1896 Athens Aquatics Swimming HAJOS, Alfred HUN Men 100M Gold
Freestyle
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 1/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
:::
Let's add the count variable and make changes to the dataset. :::
count=c(1)
summer$MedalCount=count
summer$Athlete=as.character(summer$Athlete)
:::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 2/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
options(repr.plot.width=6, repr.plot.height=6)
world <- map_data(map="world")
world <- world[world$region != "Antarctica",] #
y=ddply(summer, .(Country,Medal), numcolwise(sum))
sPDF <- joinCountryData2Map( y
,joinCode = "ISO3"
,nameJoinColumn = "Country")
mapCountryData(sPDF
,nameColumnToPlot='MedalCount')
209 codes from your data successfully matched countries in the map
140 codes from your data failed to match with a country code in the map
159 codes from the map weren't represented in your data
:::
To enable effective visualization of data, we will filter out the data for the top 5 countries overall. We will identify
the top 10 countries with the highest number of medals and then plot various charts to better understand their
performance over the years. :::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 3/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
Countries=as.data.frame(table(summer$Country,summer$MedalCount))
colnames(Countries)=c("Country","a","MedalCount")
Countries=Countries[order(-Countries$MedalCount),]
CountriesFilter=head(Countries,n=5)
topCountryFilter=summer[summer$Country %in% CountriesFilter$Country,]
options(repr.plot.width=6, repr.plot.height=3)
x=ddply(topCountryFilter, .(Country,Year), numcolwise(sum))
ggplot(x,aes(Year,MedalCount,color=Country,group=Country))+geom_point()+geom_line()
:::
1. USA has been the consistent high performer in the olympic Games, except for a period between 1950-
1980, where Soviet Russia won more medals than USA
2. Soviet Union won about 450 medals in teh 1980 games, highest ever by a country
3. Another interesting thing to note is that there is no China in the list of top most medal winning countries
4. Performance of Germany skyrocketed between 1950-1980, after going down again in the events
thereafter
5. Great Britain and France have had a very similar performance in terms of number of medals won :::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 4/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
:::
Let's know try and figure out who were the best performing athletes over the entire history of Olympic Games.
Let's also look at their sports, countries and total number of medals won by these athletes. :::
tab=as.data.frame(table(summer$Athlete,summer$MedalCount))
colnames(tab)=c("Athlete","a","MedalCount")
topAthelete=tab[order(-tab$MedalCount),]
topAthelete=head(topAthelete,n=20)
topAthelete$Athlete=as.character(topAthelete$Athlete)
:::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 5/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
:::
options(repr.plot.width=6, repr.plot.height=3)
y=ddply(topAtheleteFilter, .(Sport,Medal), numcolwise(sum))
ggplot(y,aes(x=reorder(Sport,MedalCount),y=MedalCount,fill=Medal,group=Medal))+geom_b
ar(stat='identity')
:::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 6/7
08/09/2023, 16:05 59e75f7212024afe8a2f519b64228155.knit
options(repr.plot.width=6, repr.plot.height=6)
y=ddply(summer, .(Sport,Medal), numcolwise(sum))
ggplot(y,aes(x=reorder(Sport,MedalCount),y=MedalCount,fill=Medal,group=Medal))+geom_b
ar(stat='identity') +coord_flip()
:::
file:///home/student/Downloads/vertopal.com_20mia1032-fda-lab-5/59e75f7212024afe8a2f519b64228155.html 7/7