There are two tasks in this homework. The tasks are very open. You must do at least the bare minimum on both tasks (so as to get the practice), and chose ONE of the tasks for somewhat deeper analysis. You choose which one you want to prioritize - whatever inspires you most.
library(haven)
library(ggplot2)
library(dplyr)
library(sf)
library(reshape2)
library(wbstats)
library(gtrendsR)
library(viridis)
library(maps)
index_search <- wbsearch(pattern = "urban population")
world_map <- rnaturalearth::ne_countries(scale = 50, returnclass = "sf")
pol_urban <- wb(country = "countries_only",
indicator = "SP.URB.TOTL.IN.ZS", startdate = 2021, enddate = 2021)
map_urban <- left_join(world_map, pol_urban, by = c("iso_a2" = "iso2c"))
urban_graph <- ggplot(map_urban) +
geom_sf(aes(fill = value)) +
scale_fill_viridis("Percentage")+
ggtitle("Percentage of Urban Population by Country in 2021") +
theme_bw()+
labs(caption = "Data Source: World Bank") +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
plot.caption = element_text(size = 10, face = "bold"))
urban_graph
In the first task I mapped the percentage of urban population by
country in year 2021, more than half of the population resides in urban
areas in American continents, western Europe and Asia-Pacific countries
while Sub-Sahara Africa, Central Asia and South Asian have much lower
level in urban population.
country_select <- wb_data(country = c("US", "GB", "JP", "CN", "IN", "BR"),
indicator = "SP.URB.TOTL.IN.ZS", start_date = 2001, end_date = 2021)
urban_plot <-ggplot(country_select, aes(x=as.numeric(date), y=SP.URB.TOTL.IN.ZS, color= country)) +
geom_line() + ggtitle("Percentage of urban population in select countries")+
ylab("Urban Population (%)") + xlab("Year") +
theme_classic() + labs(caption = "Data Source: The World Bank")
urban_plot1 <- urban_plot + scale_x_continuous(limits=c(2001, 2021), breaks=seq(2001, 2021, 4))
urban_plot2 <- urban_plot1 + scale_y_continuous(limits=c(0, 100), breaks=seq(0, 100, 10))
urban_final <- urban_plot2 + theme(legend.direction = "vertical",
legend.text = element_text(size = 7.5, face = "bold"),
legend.key = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
plot.title = element_text(size = 13, hjust = 0.5, face = "bold"),
axis.text.x=element_text(size = 9),
axis.text.y=element_text(size = 9),
axis.title = element_text(size = 10, face = "bold"),
plot.caption = element_text(size = 10, face = "bold"))
urban_final
I investigated the change in percentage of urban population for the
six select countries for the past twenty years. China observed the most
salient increase in urban population from below 30% to over 60%; India
exhibited the lowest percentage of urban population among six countries.
All developed countries (United States, United Kingdom, and Japan) have
a higher level of urban population. Overall there exists a gap in the
percentage of urban population between the three select developed
countries and the developing countries, except Brazil.
library(gtrendsR)
country <-data("countries")
lockdown_find <- gtrends(c('lockdown'),gprop = "web", time = "2020-01-01 2022-12-31", geo='CN')
lockdown <- lockdown_find$interest_over_time
View(lockdown)
lockdown$hits <- as.numeric(as.character(lockdown$hits))
plot(lockdown[, 'date'], lockdown[, 'hits'], main='Google Search Count for Lockdown in China, 2020-2022',xlab='Year',ylab='Keyword Searches',type='l')
I used Google trends data to show the search count for keyword
“lockdown” in China since the Covid-19 pandemic, the plot indicated that
during the initial outbreak in Wuhan and the following month, the search
count reached its peak and decreased dramatically afterwards. During the
mid-2020 and a full year of 2021 the search count fluctuates at minimal
level but skyrocketed in early 2022 during the surge of omicron variant
and showed a free fall again in mid-2022.