Today we will investigate a data set from http://www.gapminder.org, a site which contains a wealth of data and visualizations related to health, wealth, population, etc. of countries of the world.
The data is available in package gapminder as a tibble object named gapminder. Install the package in your console with install.packages("gapminder") and load it along with other packages by
library(gapminder)
library(tidyverse)
library(RColorBrewer)
gapminder
class(gapminder)
[1] "tbl_df" "tbl" "data.frame"
We’ll create an object named gapminder_df that only has class data.frame. Hence, we remove class tbl_df and tbl.
gapminder_df <- gapminder
attr(gapminder_df, which = "class") <- "data.frame"
class(gapminder_df)
[1] "data.frame"
Object gapminder has six variables:
To see the HTML file for Lab 3 visit http://rpubs.com/shawnsanto/sta523-fa19-lab3
For exercises 1 - 5 perform the task using both gapminder and gapminder_df. Focus on the differences in results between the two data frames to get a better understanding of the tibble object.
Extract the third row.
Extract the third column.
Extract the third column so the result is a data frame.
Extract the first and last columns.
Extract the last 20 rows without using the fact that you know there are 1704 rows of data.
What years are in the data set? Hint: unique.
How many countries since 1960 had a median life expectancy of at least 80?
Create a new variable named pop_scale for gapminder_df that is defined as pop / 10000.
What was the mean life expectancy for Europe in 1957? How about in 2007?
Which country had the highest median life expectancy in 1957? How about in 2007?
Use object gapminder to recreate the plots using functions in package ggplot2. To see the plots you will need to visit http://rpubs.com/shawnsanto/sta523-fa19-lab3
Non-obvious plot features
color = "blue", alpha = .2base_size = 20Non-obvious plot features
gapminder for Americas and years 1957, 1982, 2007.show.legend = FALSENon-obvious plot features
gapminder so it does not contain Oceaniacolors = brewer.pal(9, "Reds")Non-obvious plot features
gapminder so it does not contain Oceaniaalpha = .3x to a log10 scale