Skip to content

Instantly share code, notes, and snippets.

@erzk
Created March 20, 2016 12:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save erzk/0713d5234ba1a3bc8fb8 to your computer and use it in GitHub Desktop.
Kaggle dataset analysis - World University Rankings
# 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