Kaggle dataset analysis - World University Rankings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# countries by the number of universities in the CWUR ranking | |
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
library(rworldmap) | |
cwur <- read.csv("cwurData.csv") | |
# data frames with the universities and count them by country | |
cwurCount <- | |
cwur %>% | |
group_by(country) %>% | |
summarise(count=n()) | |
# only top 100 universities | |
cwurCount100 <- | |
cwur[1:100,] %>% | |
group_by(country) %>% | |
summarise(count=n()) | |
p1 <- ggplot(cwurCount, | |
aes(x=reorder(country, -count), y=count, fill=country)) + | |
geom_bar(stat="identity") + | |
coord_flip() + | |
theme(legend.position="none") + | |
labs(x="Count",y="Country") + | |
ggtitle("Countries by number of universities in CWUR") | |
p1 | |
# join to a coarse resolution map | |
country_map <- joinCountryData2Map(cwurCount100, | |
joinCode="NAME", | |
nameJoinColumn="country") | |
# getting a colour scheme from the RColorBrewer package | |
colourPalette <- brewer.pal(7,'RdPu') | |
mapParams <- mapCountryData(country_map, | |
nameColumnToPlot="count", | |
catMethod="fixedWidth", | |
colourPalette=colourPalette, | |
mapTitle = "Countries by number of universities in Top 100 CWUR") | |
do.call(addMapLegend, c(mapParams | |
,legendLabels="all" | |
,legendWidth=0.5 | |
,legendIntervals="data")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment