library(tidyverse)
library(ggplot2)
library(dplyr)
library(readxl)
library(plotly)
options(scipen=999)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
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 ⭐
<- read_excel("C:/Users/Julian/Desktop/Amherst CS/DACSS602/601_Fall_2022/posts/_data/Total_cost_for_top_15_pathogens_2018.xlsx",skip = 3) rawData
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 found
Briefly 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.
<- rawData%>%
tidy rename(PathogenName = 1)
Error in rename(., PathogenName = 1): object 'rawData' not found
<- tidy%>%
tidy slice(1:(n()-8))
Error in slice(., 1:(n() - 8)): object 'tidy' not found
tidy
Error in eval(expr, envir, enclos): object 'tidy' not found
Are 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%>%
tidymutate(severity= case_when(
<500000 ~ "Mild",
Cases<2000000) ~ "Moderate",
(Cases> 2000000 ~ "Extreme"
Cases ))
Error in mutate(., severity = case_when(Cases < 500000 ~ "Mild", (Cases < : object 'tidy' not found
## calculating some stats
<- median(tidy$Cost) medianCost
Error in median(tidy$Cost): object 'tidy' not found
<- mean(tidy$Cost) meanCost
Error in mean(tidy$Cost): object 'tidy' not found
<- sd(tidy$Cost) sdCost
Error in is.data.frame(x): object 'tidy' not found
<- sd(tidy$Cases) sdCases
Error in is.data.frame(x): object 'tidy' not found
Univariate 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 found
histogramCases
Error 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 cases
<-
PointCases %>%
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 found
PointCases
Error in eval(expr, envir, enclos): object 'PointCases' not found
Now 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))
histogramCost
Error 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 found
PointCost
Error in eval(expr, envir, enclos): object 'PointCost' not found
Bivariate 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
<- tidy %>%
biVariate filter(severity!="Extreme") %>%
ggplot( aes(Cases, Cost, color=severity,label=PathogenName)) +
geom_point() +
theme_bw()
Error in filter(., severity != "Extreme"): object 'tidy' not found
ggplotly(biVariate)
Error in ggplotly(biVariate): object 'biVariate' not found
Any additional comments?