You will write up your homework in an Rmarkdown document.


Part I - Make these plots!

Here is a chance to test out the skills you worked on in class. A few things to keep in mind as you work your way through making these plots:

Instead of loading in a dataset, this time we will install the package (if you have not already done so in class) gapminder. This is a data package. After you have installed and loaded the library gapminder, you can access the data by typing gapminder

library(gapminder)

gapminder

   

1) Plot 1

2) Plot 2

3) Plot 3

4) Plot 4

5) Plot 5

6) Plot 6


Part II - Make these plots and then some!

7) Plot 7

8) Question 8

Create a data.frame of the mean life expectancies for each continent. You should end up with a data.frame like this

## Source: local data frame [5 x 2]
## 
##   continent     mean
##      (fctr)    (dbl)
## 1    Africa 48.86533
## 2  Americas 64.65874
## 3      Asia 60.06490
## 4    Europe 71.90369
## 5   Oceania 74.32621

Part II - Troubleshooting practice


Don’t worry, there is more to read here than actually do. This is mostly a pep talk. The actual homework can be found below

For a beginner programmer, often one of the hardest things is knowing when you’re doing something really wrong, or when you are just making a silly mistake. This is confounded by complicated error messages. But, remember, the computer is trying to help you by giving you any error message at all. Embrace error messages and use them. Googling the answer for yourself is likely faster than even asking a friend. This component of this week’s homework is about practicing your troubleshooting and googling skills.

Some pointers (for beyond this assignment):

  • check your typing
  • check your typing… again
  • actually read the error message, you may understand more words than you think

When googling:

  • start by looking for the most simple looking answer
  • personally I choose stackoverflow answers at the top of a google search over any others
  • sometimes it just takes time to find the right vocabulary

Asking good questions on forums, or mailing lists is hard. But writing good questions is more likely to get you a better answer. When asking for help online (modified from the stackoverflow ‘how-to-ask’ guidelines:

  • demonstrate that you have already looked for a question similar to yours
  • write a specific and concise title describing the specific problem (you can practice this on our issues board)
  • introduce your problem (verbal description)
  • include reproducible code (e.g., simplify your problem using a small made up dataset) see “How to create a Minimal, Complete, and Verifiable example”

Find the mistakes!!!!

First, get yourself setup by running the following code. (You may copy and paste this so that you don’t introduce any extra mistakes to fix! But depending on what you have set as your working directory, you may need to adjust the path to where your hw_gapminder.csv file is).

Download this modified gapminder dataset.

library(ggplot2)

hw_gapminder <- read.csv('./hw_gapminder.csv')
mean_lifeExp <- mean(hw_gapminder$lifeExpe)

small_set <- hw_gapminder[c(1, 2, 3, 4, 1300:1304), ('country', 'continent', 'year')]

mean_gdp <- mean(hw_gapminder$gdpPercap)

max_country <- dplyr::filter(gapminder, lifeExp = max(lifeExp))

The desired outcomes are:

mean_lifeExp
## [1] 59.47444
small_set
##                    country continent year
## 1              Afghanistan      Asia 1952
## 2              Afghanistan      Asia 1957
## 3              Afghanistan      Asia 1962
## 4              Afghanistan      Asia 1967
## 1300 Sao Tome and Principe    Africa 1967
## 1301 Sao Tome and Principe    Africa 1972
## 1302 Sao Tome and Principe    Africa 1977
## 1303 Sao Tome and Principe    Africa 1982
## 1304 Sao Tome and Principe    Africa 1987
mean_gdp
## [1] 7210.019
max_country
##   country continent year lifeExp       pop gdpPercap
## 1   Japan      Asia 2007  82.603 127467972  31656.07