library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.1.8
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(ggfortify)
library(htmltools)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
setwd("C:/Users/amani/OneDrive/Desktop/Data110")
nations <- read_csv("nations.csv")
## 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.
nations <- read_csv("nations.csv") %>%
mutate(gdp_tn = gdp_percap*population/10^12 )
## 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.
random <- nations %>%
filter(iso3c == "NZL" | iso3c == "GRC" | iso3c == "LKA" | iso3c == "QAT" ) %>%
arrange(gdp_tn)
filtered_nations <- nations %>%
filter(country %in% c("NZL", "GRC", "LKA", "QAT"))
ggplot(random, aes(x = year, y = gdp_tn, color = country)) +
xlab("year") +
ylab("GDP (trillions)") +
ggtitle("GDP in Trillions by Year") +
theme_light()+
theme(plot.title = element_text(hjust=0.5))
ggplot(random, aes(x = year, y = gdp_tn, color = country)) +
geom_point() +
geom_line() +
xlab("Year") +
ylab("GDP (trillions)")+
ggtitle("GDP in Trillions by Year") +
scale_color_brewer(palette = "Set1") +
theme_dark()+
theme(plot.title = element_text(hjust = 0.8))
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_line()`).
summary(random$gdp_tn, na.rm = TRUE)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.04046 0.07636 0.13496 0.14942 0.20484 0.34520 10
library(dplyr)
mutate(gdp_tn = as.numeric(gdp_tn)) + %>% #convert gdp_tn to numeric
random_summary <- random %>%
group_by(region, year) %>%
summarise(gdp_tn= sum(gdp_tn, na.rm = TRUE), .groups = 'drop')
ggtitle("GDP in Trillions by Year") +
ggplot(random_summary, aes(x=year,y = gdp_tn, fill=region)) +
geom_area() +
scale_fill_brewer(palette = "set2")
## Warning in pal_name(palette, type): Unknown palette set2
## NULL
random_summary <- random %>%
group_by(region, year) %>%
summarise(gdp_tn= sum(gdp_tn, na.rm = TRUE), .groups = 'drop')
ggplot(random_summary, aes(x=year,y = gdp_tn, fill=region)) +
xlab("Year") +
ylab("GDP (trillions)") +
ggtitle("GDP in Trillions by Year in Regions") +
geom_area(color = "white",size= 0.5) +
scale_fill_brewer(palette = "set2")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## Warning in pal_name(palette, type): Unknown palette set2