Problem 1

For a data set of your choosing, make a faceted plot using the trelliscopejs package. You may make any type of plot; scatter plot, histogram, etc. but, as mentioned in the discussion below, you must explain why you chose this plot and what you are investigating about the variable you are graphing.

The trelliscope plot must include one cognostic measure of your own. Include a description of what it is and what information this measure gives.

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.5.2
library(trelliscopejs)
## Warning: package 'trelliscopejs' was built under R version 4.5.2
## This package is no longer maintained. Please use the 'trelliscope' package instead (see https://github.com/trelliscope/).
gap <- gapminder %>%
  filter(continent == "Americas") %>%

  group_by(country) %>%
  mutate(
    gdp_range = max(gdpPercap, na.rm = TRUE) - min(gdpPercap, na.rm = TRUE),,
    life_range = max(lifeExp) - min(lifeExp),
  )

gap$gdp_range <- cog(
  gap$gdp_range,
  desc = "Range of GDP per capita"
)

gap$life_range <- cog(
  gap$life_range,
  desc = "Range of life expectancy"
)

ggplot(gap, aes(year, lifeExp)) +
  geom_line() +
  geom_point(color = "black", size = 1.5)+
  labs(
    title = "Life Expectancy Over Time in the Americas",
    x = "Year",
    y = "Life Expectancy"
  ) +
  facet_trelliscope(
    ~ country + continent,
    name = "Americas_Gapminder_Data",
    desc = "Life expectancy Trends in the Americas",
    path = "americas_trelliscope",
    nrow = 1,
    ncol = 2,
    scales = c("same", "sliced")
  )
## using data from the first layer

Description

For this assignment, I used the gapminder dataset, which includes information about different countries over many decades. This dataset includes information regarding population, GDP per capita, and life expectancy. I chose to graph life expectancy over time in the Americas because it is a straightforward way to see how Southern and Northern American countries have changed and draw inferences on how historical events can affect a country’s life expectancy. Plotting the variables in a line plot makes it easy to observe whether life expectancy trends and compare the shape to other countries. However, by plotting the points directly, we are also being transparent about what years we are observing.

Facetting the trelliscope by country made the most sense so each panel focuses on one country within the Americas. By limiting the data to just one continent, the user isn’t too overwhelmed by the number of graphs available. Along with that, it makes comparisons amongst Northern and Southern American countries more meaningful since historical contexts would be shared by countries in close proximity.

A challenge I encountered was creating an effective cognostics that was not already included in the automatically made cognostics like mean, median, and max. In order to create new cognostics, I needed to think about what would be the most important to see and what would be helpful to see. The life expectancy range was important to see in order for the user to engage in investigating the largest or smallest changes in life expectancy. The GDP range is to give context to the life expectancy range. A smaller, less profitable economy could reflect on the health of the people and therefore change the life expectancy, so this seemed like a logical answer to my custom cognostic issue.