You will write up your homework in an Rmarkdown document.
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:
1) Plot 1
2) Plot 2
3) Plot 3
4) Plot 4
5) Plot 5
6) Plot 6
7) Plot 7
8) Plot 8
a. 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
## 1 Africa 48.86533
## 2 Americas 64.65874
## 3 Asia 60.06490
## 4 Europe 71.90369
## 5 Oceania 74.32621
b. Plot the density plot of life expectancies for each continent and draw a vertical line to mark the mean life expectancy for each continent.
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):
When googling:
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:
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 <- hw_gapminder$country[which(hw_gapminder$lifeExp = max(hw_gapminder$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
## [1] "Japan"