library(shiny)
library(readr)
library(plotly)
library(vegalite)
library(skimr)
library(kableExtra)
df <- read_csv("https://raw.githubusercontent.com/charleyferrari/CUNY_DATA_608/master/module3/data/cleaned-cdc-mortality-1999-2010-2.csv")
df <- data.frame(df)
skim(df)
| Name | df |
| Number of rows | 9961 |
| Number of columns | 6 |
| _______________________ | |
| Column type frequency: | |
| character | 2 |
| numeric | 4 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| ICD.Chapter | 0 | 1 | 9 | 99 | 0 | 19 | 0 |
| State | 0 | 1 | 2 | 2 | 0 | 51 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| Year | 0 | 1 | 2004.52 | 3.45 | 1999 | 2002.0 | 2005 | 2008.0 | 2010.0 | ▇▅▅▅▇ |
| Deaths | 0 | 1 | 2928.70 | 7153.09 | 10 | 177.0 | 667 | 2474.0 | 96511.0 | ▇▁▁▁▁ |
| Population | 0 | 1 | 5937895.69 | 6551952.76 | 491780 | 1728292.0 | 4219239 | 6562231.0 | 37253956.0 | ▇▂▁▁▁ |
| Crude.Rate | 0 | 1 | 52.15 | 80.37 | 0 | 4.6 | 24 | 50.5 | 478.4 | ▇▁▁▁▁ |
As a researcher, you frequently compare mortality rates from particular causes across different States. You need a visualization that will let you see (for 2010 only) the crude mortality rate, across all States, from one cause (for example, Neoplasms, which are effectively cancers). Create a visualization that allows you to rank States by crude mortality for each cause of death.
df1<-filter(df, Year == "2010")
unique(df1[1])%>%
kbl(caption = "Causes of Death in 2010") %>%
kable_classic(full_width = F, html_font = "Cambria")%>%
kable_styling(latex_options = "HOLD_position")
| ICD.Chapter | |
|---|---|
| 1 | Certain infectious and parasitic diseases |
| 52 | Neoplasms |
| 103 | Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism |
| 154 | Endocrine, nutritional and metabolic diseases |
| 205 | Mental and behavioural disorders |
| 256 | Diseases of the nervous system |
| 307 | Diseases of the circulatory system |
| 358 | Diseases of the respiratory system |
| 409 | Diseases of the digestive system |
| 460 | Diseases of the skin and subcutaneous tissue |
| 506 | Diseases of the musculoskeletal system and connective tissue |
| 557 | Diseases of the genitourinary system |
| 608 | Pregnancy, childbirth and the puerperium |
| 632 | Certain conditions originating in the perinatal period |
| 683 | Congenital malformations, deformations and chromosomal abnormalities |
| 734 | Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified |
| 785 | External causes of morbidity and mortality |
ui <- fluidPage(
selectInput(inputId = "Cause",
label = "Choose a Cause of Death",
df1$ICD.Chapter),
plotlyOutput("plot")
)
server <- function(input, output) {
output$plot <- renderPlotly({
plot_ly(filter(df1, ICD.Chapter == input$Cause), x = ~State, y = ~Crude.Rate, type = 'bar') %>%
layout(title = paste('Crude Mortality Rate of',input$Cause,'by State in 2010'),
xaxis = list(showgrid = FALSE, categoryorder = "total descending"),
yaxis = list(showgrid = FALSE, title = "Crude Mortality Rate"))
})
}
shinyApp(ui=ui, server=server)
Often you are asked whether particular States are improving their mortality rates (per cause) faster than, or slower than, the national average. Create a visualization that lets your clients see this for themselves for one cause of death at the time. Keep in mind that the national average should be weighted by the national population.