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.
##Create a new variable
nations <- Nations %>%mutate(gdp_trillion = gdp_percap * population /10^12)head(nations)
# A tibble: 6 × 11
iso2c iso3c country year gdp_percap population birth_rate neonat_mortal_rate
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 AD AND Andorra 1996 NA 64291 10.9 2.8
2 AD AND Andorra 1994 NA 62707 10.9 3.2
3 AD AND Andorra 2003 NA 74783 10.3 2
4 AD AND Andorra 1990 NA 54511 11.9 4.3
5 AD AND Andorra 2009 NA 85474 9.9 1.7
6 AD AND Andorra 2011 NA 82326 NA 1.6
# ℹ 3 more variables: region <chr>, income <chr>, gdp_trillion <dbl>
ggplot(filtered_data, aes(x=year, y=gdp_trillion, color = country)) +geom_point()+geom_line()+scale_color_brewer(palette ="Set1") +labs(title ="GDP Over the Most Popluated Countries",X ="Year",Y ="GDP ($trillion)",Color ="Country")+theme_minimal()
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
head(summarise_data)
# A tibble: 6 × 3
# Groups: region [1]
region year GDP
<chr> <dbl> <dbl>
1 East Asia & Pacific 1990 5.52
2 East Asia & Pacific 1991 6.03
3 East Asia & Pacific 1992 6.50
4 East Asia & Pacific 1993 7.04
5 East Asia & Pacific 1994 7.64
6 East Asia & Pacific 1995 8.29
Create Chart #2
ggplot(summarise_data, aes(x= year, y = GDP, fill = region))+geom_area(color="white", size =0.2) +scale_fill_brewer(palette ="Set2") +labs(title ="Total GDP by Region Over Time",x ="Year",Y ="Total GDP (Trillions)",fill ="Region") +theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.