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)
library(trelliscopejs)
## This package is no longer maintained. Please use the 'trelliscope' package instead (see https://github.com/trelliscope/).
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ lubridate 1.9.4 ✔ tibble 3.3.0
## ✔ purrr 1.1.0 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# read in data
life_exp <- read.csv("Life_Exp.csv")
# creating plot
life_exp %>%
group_by(Year) %>%
# create cognostic variable of gender gap
mutate(Gender_Gap = cog(mean(Female_life_exp_years - Male_life_exp_years),
desc = "Average Gender Gap",
default_label = TRUE)) %>%
# make plot
ggplot(aes(x = Female_life_exp_years, y = Male_life_exp_years)) +
geom_point(alpha = 0.15) +
labs(x = "Female Life Expectancy", y = "Male Life Expectancy") +
# use trelliscope package
facet_trelliscope( ~Year,
name = "Female and Male Life Expectancies",
desc = "Faceted by Year",
nrow = 2, ncol = 2,
scales = c("same", "same"),
self_contained = TRUE,
path = ".")
## using data from the first layer
Description 2-3 paragraphs.
Describe the data set. Explain the variable you are graphing in your plots and the reason you are investigating with it. Discuss the reason/motivation you chose the variable to facet on, and what insight or trend you are attempting to investigate. Discuss any challenges you had in making the graphs and how you dealt with these challenges. Name at least one cognostic measure (this can include the cognostic you created or be different) the reader could investigate, and explain any insight they might gain from it.
This data set contains female and male life expectancies across the United States from 1985 to 2010. The data is organized by state and county, with over 80,000 rows of data. In the plots, we compare female and male life expectancies. The plots are faceted by year, meaning each plot contains data from all the counties in each specific year. We are able to see if the life expectancies have changed over the years, and if male or female has changed more. If we compare 1985 to 2010, we can see that the life expectancy for both females and males increased.
The main challenge with this graph was ensuring we were comparing the graphs fairly. At first, the points did not seem like they changed over the years. This was because the scales were adapting to the data, meaning that the data points were centered on the graph. After we set the scales to “same,” this issue was resolved. The graphs then showed a noticeable difference over the years.
The cognostic measure I chose to investigate was the gender life expectancy gap. This is calculated each year. When the value is positive, it means the females have higher life expectancies. When the value is negative, the males have higher life expectancies. We can see a steady decrease over the years, with the values starting around 7, and decreasing to 5. This is showing that the life expectancy gap between the two groups is constantly shrinking. With all the values being positive, we know that females consistently have a higher life expectancy.
knit the file to an html document
publish this to an RPubs page.
grading: trelliscope plot[25 points], discussion[25 points]
Note: you can add a url directly to the text and it will be active in the html (and word document if you knit to that)
Example: https://www.google.com