library(readr)
library(ggplot2)
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(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(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v tibble 2.1.3 v purrr 0.3.2
## v tidyr 1.0.0 v stringr 1.4.0
## v tibble 2.1.3 v forcats 0.4.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x plotly::filter() masks dplyr::filter(), stats::filter()
## x dplyr::lag() masks stats::lag()
find csv file (which was already manipulated to create GDP for each country in trillions). I need to copy someone else’s code who did it correctly using mutate and practice with it.
setwd("C:/Users/Don A/Documents/Don's files/MC")
week7hw1 <- read_csv("nations1.csv")
## Parsed with column specification:
## cols(
## iso2c = col_character(),
## iso3c = col_character(),
## country = col_character(),
## year = col_double(),
## gdp_percap = col_double(),
## population = col_double(),
## birth_rate = col_double(),
## neonat_mortal_rate = col_double(),
## region = col_character(),
## income = col_character(),
## gdpt = col_double()
## )
I was doing something wrong and couldn’t correctly filter with dplyr the five countries I wanted: China, India, USA, Indonesia, and Brazil (the five largest in population size). So I sorted the csv file and deleted all other countries. I did follow the instructions and created a column for gdp in USD $ trillions.
ggplot(data = week7hw1) +
geom_point(mapping = aes(x = year, y = gdpt, group = country, color = country )) +
geom_line(mapping = aes(x = year, y = gdpt, group = country, color = country)) +
ggtitle("China's Rise to Become the Largest Economy") +
labs(x = "year", y = "GDP ($ trillions)") +
scale_color_brewer(palette = "Set1")
## Warning: Removed 246 rows containing missing values (geom_point).
## Warning: Removed 246 rows containing missing values (geom_path).
Not sure what the “Removed 246 rows” error message is about