Skip to content

Instantly share code, notes, and snippets.

@tommyhuang1
Created February 5, 2017 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyhuang1/4062f71a434c054acf8b6dd1e2e72834 to your computer and use it in GitHub Desktop.
Save tommyhuang1/4062f71a434c054acf8b6dd1e2e72834 to your computer and use it in GitHub Desktop.
Death Trend by Race Ethnicity
# ui.R
menuSubItem("Trend By Leading Cause and Race Ethnicity", tabName = "TrendByLeadingCauseAndRace",icon = icon("line-chart"))
tabItem(tabName = "TrendLineByRaceEthnicity",
fluidRow(column(8,plotOutput("TrendLineByRaceEthnicity")),
column(4,checkboxGroupInput("Race_Ethnicity",label = h3("Select the race ethnicity"),
choices = c("Asian and Pacific Islander" = "Asian and Pacific Islander","Black Non-Hispanic" = "Black Non-Hispanic",
"White Non-Hispanic" = "White Non-Hispanic","Hispanic" = "Hispanic"),selected = "Hispanic",width = 600))))
#server.R
output$TrendLineByRaceEthnicity<-renderPlot({
g<-group_by(data,Year,Race_Ethnicity)
s<-summarise(g,Total_Death = sum(as.numeric(Deaths),na.rm=TRUE))
ggplot(s[s$Race_Ethnicity%in%input$Race_Ethnicity,],aes(Year,Total_Death)) + geom_point() +
geom_line(aes(color = Race_Ethnicity)) + ylab('Total Death') +
ggtitle('2007-2014 Death Trend') + theme(plot.title = element_text(hjust = 0.5)) +
guides(fill=guide_legend(title = "Race Ethnicity")) + theme(plot.title = element_text(size = 15, face = "bold"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment