Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.