Submit this file (after adding your name after “author”) using Canvas. Make sure to label your plots! Then load packages that you will use.
dslabs and define the dataset
gapminder as gapminder <- as_tibble(gapminder).library(dslabs)
library(tidyverse)
data(gapminder)
gapminder <- as_tibble(gapminder)
gdp_per_cap
corresponding to gdp divided by
population.library(dplyr)
library(gapminder)
##
## Attaching package: 'gapminder'
## The following object is masked _by_ '.GlobalEnv':
##
## gapminder
## The following object is masked from 'package:dslabs':
##
## gapminder
data("gapminder")
gdp <- c(1000,2000,3000,4000,5000)
population <- c(1000, 2000, 3000, 4000, 5000)
gdp_per_cap <- gdp / population
mean_pop, removing missing values and assigning the output
to a new object called gapminder_new.gapminder_new <- gapminder %>%
group_by(continent, year) %>%
summarise(mean_pop = mean(population, na.rm = TRUE))
## `summarise()` has grouped output by 'continent'. You can override using the
## `.groups` argument.
library(ggplot2)
gapminder_new %>%
filter(year != 2016) %>%
ggplot(aes(x = year, y = mean_pop, color = continent)) +
geom_line() +
ggtitle("Average Population by Continent and Year") +
xlab("Year") +
ylab("Population")
Call this graph g.
library(ggplot2)
g <- gapminder %>%
filter(year == 2014) %>%
ggplot(aes(x = lifeExp)) +
geom_histogram(binwidth = 5, boundary = 45, color = "white") +
ggtitle("Life Expectancy in 2014") +
xlab("Life Expectancy (years)") +
ylab("Frequency")
library(ggplot2)
g <- gapminder %>%
filter(year == 2014) %>%
ggplot(aes(x = infantMortality, y = fertility)) +
geom_point(size = 3, alpha = 0.5, color = "#009E73") +
ggtitle("Fertility vs Infant Mortality in 2014") +
xlab("Infant Mortality") +
ylab("Fertility Rate")