Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dplyr)
- library(shiny)
- library(ggplot2)
- library(readxl)
- master<-read_excel("~/Domaca Naloga/selected-trend-table-from-health-united-states-2011.-leading-causes-of-death-and-numbers-of-deaths-by-sex-race-and-hispanic-origin-united-states-1980-and-2009.xlsx")
- uni <- unique(as.factor(master$Cause_of_death))
- # Define UI for application that draws a histogram
- ui <- fluidPage(
- # Application title
- titlePanel("Leading Causes of Death and Numbers of Deaths "),
- HTML("<p>In the table belowe we have data on the number of deaths, throughout the years starting since 1980 to 2009, for a number of differnet causes.
- Including various diseases, suicide and homicide. This is a dataset hosted by the Centers for Disease Control and Prevention.
- Based on this dataset I will try to find out things like: what was the leading couse of death at the begining, end and throughout this period,
- have more people died at the end of the period or at the begining, are there diseases that affect a certan race/ethnic group (or Geographycal location) more thean others.</p>"),
- conditionalPanel(condition = "input.show_data == true", h3("Data table")),
- DT::dataTableOutput(outputId = "deathtable"),
- # Sidebar with a slider input for number of bins
- sidebarLayout(
- sidebarPanel(
- selectInput(inputId = "Disease",
- label = "Select Disease:",
- choices = uni,
- selected = "All causes",
- selectize = TRUE),
- wellPanel(
- # Show data table
- checkboxInput(inputId = "show_data",
- label = "Show data table",
- value = TRUE)
- ),
- HTML("<h3>Data interpretation</h3>
- <p>From the dropdown menu above we can choose between different causes of death.
- On the right we get a chart showing us if the the number of deaths is growing or not for different races/ethnic groups.
- From the data we can conclude that while some diseases are occuring less the other that have grown in time. We can also see that there are diseases
- that appear to affect more certan races/ethnic groups. That can be caused by Geographycal or Biologycal predispositions.
- Overall when we select all causes we can see that the number of deaths has grown from 200 000 to 250 000.</p>")
- ), #closing sidebarPanel
- # Show a plot of the generated distribution
- mainPanel(
- plotOutput(outputId = "scatterplot"),
- width = 7
- )
- ), #closing sidebarLayout
- plotOutput(outputId = "barchart"),
- HTML("<h3>Data interpretation</h3>
- <p>From the bar char above we can see the number of deaths for groups throughout the years,
- and from the chart below we can see the number of deaths by diseases.</p>"),
- plotOutput(outputId = "barchart2")
- )#closing fluidPage
- # Define server logic required to draw a histogram
- server <- function(input, output) {
- output$deathtable <- DT::renderDataTable(
- if(input$show_data){
- DT::datatable(data = master[, 1:4],
- options = list(pageLength = 10),
- rownames = FALSE)
- }
- )
- output$scatterplot <- renderPlot({
- #req(input$category)
- req(input$Disease)
- filter(master, Cause_of_death==input$Disease) %>%
- ggplot(., aes(x= Year, y=Deaths, group=Group, color=Group)) +
- geom_line(size=1.5) + geom_point(shape=4, size=2.5)+
- scale_color_brewer(palette="Set2")+
- theme_dark()
- })
- output$barchart <- renderPlot({
- #req(input$category)
- #req(input$Disease)
- ggplot(master, aes(x= Year, y= Deaths, fill=Group)) +
- geom_bar(stat="identity", width = 9, colour="black", lwd=0.1) +
- geom_text(aes(label= ifelse(Deaths>300000,Deaths,"")), position=position_stack(vjust=0.5), colour = "white") + coord_flip() + labs(y="", x="")
- })
- output$barchart2 <- renderPlot({
- #req(input$category)
- #req(input$Disease)
- ggplot(master, aes(x= Year, y= Deaths, fill=Cause_of_death)) +
- geom_bar(stat="identity", width = 9, colour="black", lwd=0.1) +
- geom_text(aes(label= ifelse(Deaths>500000,Deaths,"")), position=position_stack(vjust=0.5), colour = "white") + coord_flip() + labs(y="", x="")
- })
- }
- # Run the application
- shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement