library(tidyverse)
library(ggplot2)
library(dplyr)
library(readxl)
library(plotly)
options(scipen=999)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)Challenge 5 Submission
Challenge Overview
Today’s challenge is to:
- read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
- tidy data (as needed, including sanity checks)
- mutate variables as needed (including sanity checks)
- create at least two univariate visualizations
- try to make them “publication” ready
- Explain why you choose the specific graph type
- Create at least one bivariate visualization
- try to make them “publication” ready
- Explain why you choose the specific graph type
R Graph Gallery is a good starting point for thinking about what information is conveyed in standard graph types, and includes example R code.
(be sure to only include the category tags for the data you use!)
Read in data
Read in one (or more) of the following datasets, using the correct R package and command. - Total_cost_for_top_15_pathogens_2018.xlsx ⭐
rawData<- read_excel("C:/Users/Julian/Desktop/Amherst CS/DACSS602/601_Fall_2022/posts/_data/Total_cost_for_top_15_pathogens_2018.xlsx",skip = 3)Error: `path` does not exist: 'C:/Users/Julian/Desktop/Amherst CS/DACSS602/601_Fall_2022/posts/_data/Total_cost_for_top_15_pathogens_2018.xlsx'head(rawData)Error in head(rawData): object 'rawData' not foundBriefly describe the data
This data set looks to be describing different foodborne illnesses and their associated case count and cost to the US.
Tidy Data (as needed)
Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.
Data needed a little tidying as shown below. While reading in the data I also cut a few unnecessary lines.
tidy <- rawData%>%
  rename(PathogenName = 1)Error in rename(., PathogenName = 1): object 'rawData' not foundtidy <- tidy%>%
  slice(1:(n()-8))Error in slice(., 1:(n() - 8)): object 'tidy' not foundtidyError in eval(expr, envir, enclos): object 'tidy' not foundAre there any variables that require mutation to be usable in your analysis stream? For example, do you need to calculate new values in order to graph them? Can string values be represented numerically? Do you need to turn any variables into factors and reorder for ease of graphics and visualization?
Document your work here.
## after some light graphing i wanted to create a qualitative variable
tidy<- tidy%>%
  mutate(severity= case_when(
    Cases<500000 ~ "Mild",
    (Cases<2000000) ~ "Moderate",
    Cases > 2000000 ~ "Extreme"
  ))Error in mutate(., severity = case_when(Cases < 500000 ~ "Mild", (Cases < : object 'tidy' not found## calculating some stats
medianCost <- median(tidy$Cost)Error in median(tidy$Cost): object 'tidy' not foundmeanCost <- mean(tidy$Cost)Error in mean(tidy$Cost): object 'tidy' not foundsdCost<- sd(tidy$Cost)Error in is.data.frame(x): object 'tidy' not foundsdCases<- sd(tidy$Cases)Error in is.data.frame(x): object 'tidy' not foundUnivariate Visualizations
histogramCases <- 
  tidy %>%
    ggplot(aes(x=Cases)) +
    geom_histogram(bins = 200,fill="#69b3a2") +
    labs(title="Number of Cases of Foodborne illness 2018",x="Cases", y = "Count")Error in ggplot(., aes(x = Cases)): object 'tidy' not foundhistogramCasesError in eval(expr, envir, enclos): object 'histogramCases' not found## seems like there is one pathogen with a very large number of cases.
# i want to try and group these different pathogens into mild moderate and extreme number of casesPointCases <- 
  tidy %>%
    ggplot(aes(y=PathogenName,x=Cases)) +
    geom_point() +
    labs(title="Cases of Foodborne illness 2018",x="Cases", y = "Pathogen")Error in ggplot(., aes(y = PathogenName, x = Cases)): object 'tidy' not foundPointCasesError in eval(expr, envir, enclos): object 'PointCases' not foundNow I look at the cost and see if there is a similar outlier
histogramCost <- 
  tidy %>%
    ggplot(aes(x=Cost)) +
    geom_histogram(bins = 100)Error in ggplot(., aes(x = Cost)): object 'tidy' not found#+
 #  scale_x_continuous(breaks = round(seq(min(tidy$Cost), max(tidy$Cost), by = 100000),1))
histogramCostError in eval(expr, envir, enclos): object 'histogramCost' not found## seems like there is one pathogen with a very large number of cases.PointCost <- 
  tidy %>%
    mutate(Cost=Cost/1000000)%>%
    ggplot(aes(y=PathogenName,x=Cost,color=severity)) +
    geom_point()+
    labs(title="Cost of Foodborne illness 2018",x="Cost(Millions)", y = "Pathogen")Error in mutate(., Cost = Cost/1000000): object 'tidy' not foundPointCostError in eval(expr, envir, enclos): object 'PointCost' not foundBivariate Visualization(s)
I am not including the Extreme case so that the graph does not need to be rescaled
#cases vs Count
# i removed the extreme case so its a bit easier to visualize
biVariate <- tidy %>%
  filter(severity!="Extreme") %>%
  ggplot( aes(Cases, Cost, color=severity,label=PathogenName)) +
    geom_point() +
    theme_bw()Error in filter(., severity != "Extreme"): object 'tidy' not foundggplotly(biVariate)Error in ggplotly(biVariate): object 'biVariate' not foundAny additional comments?