Assignment 5

Author

colton deleo

Go to the shared posit.cloud workspace for this class and open the assign05 project. Open the assign05.qmd file and complete the exercises.

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

The Grading Rubric is available at the end of this document. Note: you will receive deductions for not using tidyverse syntax in this assignment. That includes the use of filter, mutate, and the up-to-date pipe operator |>.

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)
library(gt)
library(gtExtras)

This is your work area. Add as many code cells as you need.

gapminder %>%
  filter(year == 1997) %>%
  filter(continent %in% c("Americas", "Europe")) %>%
  arrange(pop) %>%
  group_by(continent) %>%
  slice_head(n = 2) %>%
  select(country, pop, lifeExp) %>%
  pivot_wider(names_from = continent, values_from = c(pop, lifeExp)) %>%
  select(country, starts_with("Americas"), starts_with("Europe")) %>%
  gt() %>%
  tab_header(
    title = "Population and Life Expectancy for the Two Least Populated Countries in the Americas and Europe for 1997",
    subtitle = "Data from the gapminder dataset"
  ) %>%
  fmt_number(
    columns = vars(starts_with("pop")),
    decimals = 0
  ) %>%
  fmt_number(
    columns = vars(starts_with("lifeExp")),
    decimals = 1
  ) %>%
  tab_spanner(
    label = "Americas",
    columns = starts_with("Americas")
  ) %>%
  tab_spanner(
    label = "Europe",
    columns = starts_with("Europe")
  ) %>%
  tab_spanner(
    label = "Population",
    columns = starts_with("pop")
  ) %>%
  tab_spanner(
    label = "Life Expectancy",
    columns = starts_with("lifeExp")
  ) %>%
  tab_footnote(
    footnote = "Skál!",
    locations = cells_body()
  )
Adding missing grouping variables: `continent`
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
Population and Life Expectancy for the Two Least Populated Countries in the Americas and Europe for 1997
Data from the gapminder dataset
country
Trinidad and Tobago1
Jamaica1
Iceland1
Montenegro1
1 Skál!

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.