In this work, I looked at the economic growths of the four biggest countries in this world. These countries are; the US, China, Japan, and Germany. However, I also decided to add another country just for my own interests.
# install.packages("RColorBrewer")
library(ggplot2)
library(RColorBrewer)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readr)
setwd("/Users/justinpark/Desktop/Nations Dataset")
Since there is no variable for gdp of a country we need to calculate it. However, we will also need to divide the value by a trillion (1000000000000) otherwise the y axis values will be too large to handle.
nations <- read.csv("nations.csv") %>%
mutate(gdp_tn = gdp_percap*population/1000000000000)
# nations
In this assignment, we only wanted to look at the nations with the top 4 economics. These nations are, in no order, China (CHN), Germany (DEU), Japan (JPN), and the US (USA). However, I also decided to include South Korea (KOR) as its economic growth was a 20th century success story. I wanted to see how it would compare against the other 4.
modifiedlist <- nations %>%
filter(iso3c == "CHN" | iso3c == "DEU" | iso3c == "JPN" | iso3c == "USA" | iso3c == "KOR") %>%
arrange(year)
# modifiedlist
p <- ggplot() +
geom_point(data = modifiedlist, aes(x = year, y = gdp_tn, fill = country)) +
geom_line(data = modifiedlist, aes(x = year, y = gdp_tn, color = country))
p
So this is the basic graph and as you can see, it is very basic. No titles on the axes, and the colors and aethetics are both unpleasant hard to distinguish.
However, the colors for the graph above can arguably be better. However, this can be changed using the other package “RColorBrewer”. In this chunk we automatically choose 5 discrete colors for the 5 different countries.
p1 <- ggplot(modifiedlist, aes(x = year, y = gdp_tn, color = country))
p1 + geom_line() + geom_point() +
scale_color_brewer(name = "Countries", palette = "Set1") +
ggtitle("Economic Growth Over the Years") +
theme(plot.title = element_text(hjust = 0.5)) +
labs(
x = "Year",
y = "GDP (in trillion $)")
Before the points were black while the lines were very hard to distinguish. So I changed this in order to make it more pleasant to look at. The lines for each country are also very easy to tell apart, making the graph easy to read
This graph gives a very good visualization of the rapid increase in China’s economy. It has even surpassed the USA at around 2013. However, while these 2 countries have been increasing rapidly, many of the other countries are still left far behind. Even Japan, who is third, is still 13.25 trillion dollars behind. And this gap seems to only be increasing. While the bottom 3 countries generally look like linear growths, perhaps it was a different story before 1990. Nevertheless, the gap between China and the US versus all the other countries only gets larger over time. It only seems as if the countries who “rule” the world will continue to do so.