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.
data(Nations)
Warning in data(Nations): data set 'Nations' not found
#mutate from dplyr, giving the GDP of each country in trillions of dollars, by multiplying gdp_percap by population and dividing by a trillion.
Nations1 <- Nations|>mutate(GDP = gdp_percap * population /10^12)
#Select four countries to work with and filter for them
Nations2 <- Nations1|>filter(country %in%c("United Arab Emirates", "Angola", "Zimbabwe", "Zambia"))Nations2
# A tibble: 100 × 11
iso2c iso3c country year gdp_percap population birth_rate neonat_mortal_rate
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 AE ARE United… 1991 73037. 1913190 24.6 7.9
2 AE ARE United… 1993 71960. 2127863 22.4 7.3
3 AE ARE United… 2001 83534. 3217865 15.8 5.5
4 AE ARE United… 1992 73154. 2019014 23.5 7.6
5 AE ARE United… 1994 74684. 2238281 21.3 6.9
6 AE ARE United… 2007 75427. 6010100 12.8 4.7
7 AE ARE United… 2004 87844. 3975945 14.2 5.1
8 AE ARE United… 1996 79480. 2467726 19.3 6.4
9 AE ARE United… 2006 82754. 5171255 13.3 4.9
10 AE ARE United… 2000 84975. 3050128 16.4 5.6
# ℹ 90 more rows
# ℹ 3 more variables: region <chr>, income <chr>, GDP <dbl>
#Use ggplot 2 to make a chart including geomline and geompoint
Chart1 <- Nations2 |>ggplot(aes(x = country, y = GDP))+geom_point()+geom_line(color ="red")+labs(title ="GDP per trillion, for each country's year",x ="Country",y ="GDP in Trillions")+scale_color_brewer(palette ="Set1")Chart1
#Second Chart #Group by region and year with a summary of GDP
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
Nations3
# A tibble: 175 × 3
# Groups: region [7]
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
7 East Asia & Pacific 1996 8.96
8 East Asia & Pacific 1997 9.55
9 East Asia & Pacific 1998 9.60
10 East Asia & Pacific 1999 10.1
# ℹ 165 more rows
#Create second chart using Nations3 dataframe.
Chart2 <- Nations3|>ggplot(aes(x = GDP, y = region, fill = year, color = GDP))+geom_area()+scale_fill_brewer(palette ="Set2")