Rows: 5275 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): iso2c, iso3c, country, region, income
dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Select, filter and mutate
Now, we select the variables we will work with, we filter to get 4 countries (in this case I chose US, China, Japan and Germany). Then, I used the general GDP formula and created the “gdp_countries” variable.
# A tibble: 100 × 5
gdp_percap population country year gdp_countries
<dbl> <dbl> <chr> <dbl> <dbl>
1 1260. 1164970000 China 1992 1.47
2 5053. 1303720000 China 2005 6.59
3 2915. 1262645000 China 2000 3.68
4 1091. 1150780000 China 1991 1.26
5 12219. 1357380000 China 2013 16.6
6 2650. 1252735000 China 1999 3.32
7 13255. 1364270000 China 2014 18.1
8 3934. 1288400000 China 2003 5.07
9 4423. 1296075000 China 2004 5.73
10 1453. 1178440000 China 1993 1.71
# ℹ 90 more rows
Create your visualization
Now, it’s time to label and define the type of graph you will create with what you have. In this case I created a line graph using the “geom_line” function.
countries_selected_chart <-ggplot(countries_selected, aes(x = year, y = gdp_countries, color = country)) +labs(title ="China's Rise to Become the Largest Economy") +geom_line() +xlab("Year") +ylab("GDP ($ trillion)")
print(countries_selected_chart)
Adding points to your graph
In order make my graph better looking, I added some points to it using the “geom_point” function.