Submit this file (after adding your name after “author”) and the knitted html (or pdf if you have a latex distribution installed in your computer) on Canvas. Make sure to label your plots!

  1. Load the library dslabs and define the dataset gapminder as gapminder <- as_tibble(gapminder). There is another dataset called gapminder too, that is in the package gapminder. They are different, so make sure you only load dslabs. If you want to avoid confusion, you can write dslabs::gapminder to make the package explicit.
## Warning: package 'dslabs' was built under R version 4.2.3
  1. Create a new variable called gdp_per_cap corresponding to gdp divided by population.
gapminder <- mutate(gapminder, gdp_per_cap = gdp/population)
  1. Compute the average population per continent per year, call it mean_pop, removing missing values and assigning the output to a new object called gapminder_new.
gapminder_new <- gapminder %>% group_by(continent,year) %>% filter(year<2016) %>% summarise(mean_pop = mean(population, na.rm = TRUE)) 
## `summarise()` has grouped output by 'continent'. You can override using the
## `.groups` argument.
  1. Plot the average population over time, using a different color for each continent. Don’t forget to label your axes. (You may want to drop observations for 2016, here or at an earlier point, if you want to avoid a warning saying that there are NA values. This comes from missing values for 2016.)
ggplot(gapminder_new, aes(x=year,y=mean_pop/1000000, color=continent)) +ggtitle("World Population by Year and Continent in Millions") +xlab("Year") + ylab("Mean Population") +  geom_line()

  1. Create a histogram of life expectancy in 2014. Within the appropiate geom_* set:

Call this graph g.

g <- ggplot(gapminder %>% filter(year==2014), aes(x=life_expectancy,color=continent)) + geom_histogram(color="white",binwidth=5,boundary=45,fill="#d90502") + labs(title="Life Expectancy in 2014",x="Life Expectancy Rate",y="Value")
  1. Using the previous graph g, facet it by continent such that each continent’s plot is a new row. (Hint: check for help for facet_grid)
g + facet_grid(
  rows = vars(continent)
)

  1. Create a scatter plot of fertility rate (y-axis) with respect to infant mortality (x-axis) in 2014. Within the appropiate geom_*, set
ggplot(gapminder %>% filter(year==2014),aes(x=infant_mortality,y=fertility)) + geom_point(size=3,alpha=0.5,color="#009E73",na.rm = TRUE) + scale_y_continuous() + labs(title="Fertility Rate by Infant Mortality in 2014", x="Infant Mortality Rate",y="Fertility Rate")