library(tidyverse)
library(gapminder)
library(gt)
library(gtExtras)
Assignment 5
As best you can, recreate this table showing the population and life expectancy for the two least populated countries in the Americas and Europe for 1997. Your assignment must show all code in the output. Use as many code chunks as you feel necessary, I recommend first getting the output to match the output below. Hint: you will probably find it easiest to use two pivot_wider()
functions with a union()
to replicate the data layout. Use the gapminder dataset.
The Grading Rubric is available at the end of this document.
The word Skál! should link to https://www.islandshotel.is/explore-iceland/blog/icelandic-phrases/ it doesn’t in the image because it is an image. The following packages are useful and loaded for you.
library(tidyverse)
library(gapminder)
<- gapminder %>%
gap_1997 filter(year == 1997)
<- gap_1997 %>%
americas_least_pop filter(continent == "Americas") %>%
arrange(pop) %>%
slice(1:2) %>%
select(country, continent, pop, lifeExp)
<- gap_1997 %>%
europe_least_pop filter(continent == "Europe") %>%
arrange(pop) %>%
slice(1:2) %>%
select(country, continent, pop, lifeExp)
<- union(americas_least_pop, europe_least_pop)
combined <- combined %>%
pop_wide select(country, continent, pop) %>%
pivot_wider(names_from = continent, values_from = pop)
<- combined %>%
lifeexp_wide select(country, continent, lifeExp) %>%
pivot_wider(names_from = continent, values_from = lifeExp)
<- left_join(pop_wide, lifeexp_wide, by = "country", suffix = c("_pop", "_lifeExp"))
final_table final_table
# A tibble: 4 × 5
country Americas_pop Europe_pop Americas_lifeExp Europe_lifeExp
<fct> <int> <int> <dbl> <dbl>
1 Trinidad and Tobago 1138101 NA 69.5 NA
2 Jamaica 2531311 NA 72.3 NA
3 Iceland NA 271192 NA 79.0
4 Montenegro NA 692651 NA 75.4
This is your work area. Add as many code cells as you need.
Submission
To submit your assignment:
- Change the author name to your name in the YAML portion at the top of this document
- Render your document to html and publish it to RPubs.
- Submit the link to your Rpubs document in the Brightspace comments section for this assignment.
- Click on the “Add a File” button and upload your .qmd file for this assignment to Brightspace.
Grading Rubric
Item (percent overall) |
100% - flawless | 67% - minor issues | 33% - moderate issues | 0% - major issues or not attempted |
---|---|---|---|---|
Narrative: typos and grammatical errors (7%) |
||||
Document formatting: correctly implemented instructions (7%) |
||||
Accuracy of replicated image as a gt table (78% ) |
||||
Submitted properly to Brightspace (8%) |
NA | NA | You must submit according to instructions to receive any credit for this portion. |