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.


#install.packages("dslabs")
#install.packages("dplyr")
#install.packages("ggbeeswarm")
#install.packages("gapminder")
#install.packages("trelliscopejs")
#install.packages("tidyverse")

library(dslabs)  
library(ggplot2)
library(dplyr)
library(purrr)
library(trelliscopejs)
library(tidyverse)

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.


#setwd and load dataset
setwd("~/RStudioFiles")
sleepstudy = read.csv('sleep_screen_time.csv', header = TRUE, sep=",") 

view(sleepstudy)

#create a custom cognic for next day fatigue scores>=6 (High)
sleep_fatigue = sleepstudy %>%
  group_by(primary_app_category,blue_light_filter_on) %>%
  mutate(high_fatigue_pct=round(mean(next_day_fatigue_score>=6.0,na.rm=TRUE)*100,2)) %>% 
  ungroup() %>%
  mutate(high_fatigue_pct=cog(high_fatigue_pct,desc="Percentage of Users with Next Day Fatigue Higher than 6"))

#trelliscope plot 

ggplot(sleep_fatigue,aes(x=screen_time_before_bed_min,y=sleep_efficiency_pct)) +
         geom_point(alpha=0.5,size=0.8,shape=20,color="gray60")+
         geom_smooth(method="lm",se=TRUE,linewidth=1)+
         labs(title = "Pre-Bed Screen Time vs. Sleep Efficiency by App Category and Blue Light Filter",
              x="Screen Time before Bed (Minutes)",
              y="Sleep Efficiency (%)")+
         theme_minimal()+
         facet_trelliscope(~primary_app_category+blue_light_filter_on,
                           name="Sleep Screen Efficiency",
                           desc="Sleep Efficiency vs Pre-Bed Screentime Faceted by App Category and Blue-Light Filter",
                           nrow=2,
                           ncol=4,
                           path="trelliscope_widget",
                           self_contained=TRUE)

This dataset captures individuals demographics, pre-bedtime screen habits, and sleep study outcomes/next day fatigue. I chose this dataset because I have had issues with insomnia before and one of the things that helped me was developing better “bedtime habits” around screen times, caffeine, and routines. I would like to visually investigate the correlation between quality/quantity of sleep and quantity/type of pre-bedtime screen use.

In the scatterplot I chose to use “sleep_efficiency_pct” and “Screen_Time_before_bed” because efficiency felt like a better measurement of the quality of the sleep that the individual experienced rather than just total time asleep. “Screen_time_before_bed_min” was chosen as the x axis because I would want to see if the relationship between the two variables is a negative one meaning higher screen times would have lower sleep efficiency scores. I used app category and blue light status as the facet variables because these both relate to the “type” of screen time the individual used. Applying these facets in the trelliscope can allow us to easily see if certain types of application and screen use are associated with lower quality and quantity of sleep.

The variable that I chose to create a cognostic measure of is “high_fatigue_pct”. This is the percentage of users from each panel that reported a next day fatigue score greater than 6. Since just having the mean fatigue score listed for each panel could mask high clusters/outliers, this measure immediately shows which panels from the types of screen usage have the highest portion of individuals who are fatigued the next morning.


Here is my RPubs URL: http://rpubs.com/nxkst/