This project uses GDP dataset downloaded from the WorldBank Database. The dataset can be accessed in GitHub Repository
## Parsed with column specification:
## cols(
## .default = col_double(),
## country_name = col_character(),
## country_code = col_character(),
## Region = col_character(),
## indicator_name = col_character()
## )
## See spec(...) for full column specifications.
Drop non-country rows
gdp_clean <- filter(gdp, !(country_code %in% c("ARB", "CEB", "CSS","EAP", "EAR", "EAS", "ECA", "ECS", "EMU", "EUU", "FCS", "HIC", "HPC", "IBD", "IBT", "IDA", "IDB", "IDX", "INX", "LAC", "LCN", "LDC", "LIC", "LMC", "LMY", "LTE", "MIC", "MEA", "MNA", "NAC", "OED", "OSS", "PST", "PSS", "PRE", "SSA", "SSF", "TEA", "TLA", "TMN", "TSA", "TSS", "UMC", "WLD")))
gdp_cleanDrop all rows with NA in “Region” column
Transform the dataframe into long shape
## Parsed with column specification:
## cols(
## country_name = col_character(),
## country_code = col_character(),
## Region = col_character(),
## indicator_name = col_character(),
## year = col_double(),
## gdp = col_double()
## )
static_plot <- ggplot(gdp_set, aes(rank, group = country_name)) +
geom_tile(aes(y = gdp/2,
height = gdp, fill = Region,
width = 0.9), alpha = 0.8, color = NA) +
geom_text(aes(y = 0, label = paste(country_name, " ")), vjust = 0.2, hjust = 1) +
geom_text(aes(y=gdp,label = gdp_lbl, hjust=0)) +
geom_text(aes(x=30, y=max(gdp) , label = as.factor(year)), vjust = 0.2, alpha = 0.5, col = "gray", size = 20) +
coord_flip(clip = "off", expand = FALSE) +
scale_y_continuous(labels = scales::comma) +
scale_x_reverse() +
scale_fill_discrete(guide = guide_legend(title.theme = element_text(
size = 20), label.theme = element_text(size = 15))) +
theme(axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.background=element_blank(),
panel.border=element_blank(),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.grid.major.x = element_line( size=.1, color="grey" ),
panel.grid.minor.x = element_line( size=.1, color="grey" ),
plot.title=element_text(size=25, hjust=0, face="bold", colour="black", vjust=-1),
plot.subtitle=element_text(size=18, hjust=1, face="italic", color="grey"),
plot.caption =element_text(size=14, hjust=1, face="italic", color="grey"),
plot.background=element_blank(),
plot.margin = margin(2,2, 2, 4, "cm"))animated <- static_plot + transition_states(year,
transition_length = 3, state_length = 0, wrap = FALSE) +
view_follow(fixed_x = TRUE) +
ease_aes('linear')+
enter_fade()+
exit_fade() +
labs(title = 'Top 30 World GDP, 1970-2019',
subtitle = "GDP in Billions USD (constant 2010)",
caption = "Data Source: World Bank Data")