Last active
February 5, 2017 03:34
-
-
Save tommyhuang1/9d50372c34837a2cc471b17063ef0fb9 to your computer and use it in GitHub Desktop.
Top 5 Leading Causes of Death
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ui.R | |
menuSubItem("Top 5 Leading Causes", tabName = "Top5LeadingCauses", icon = icon("bar-chart")) | |
tabItem(tabName = "Top5LeadingCauses", | |
fluidRow(column(12,plotOutput("Top5LeadingCauses")))) | |
#server.R | |
output$Top5LeadingCauses<-renderPlot({ | |
groupByLeadingCause<-group_by(data,Leading.Cause) | |
summary<-summarise(groupByLeadingCause,sum = sum(Deaths,na.rm = T)) | |
ggplot(arrange(summary,desc(sum))[1:5,],aes(reorder(Leading.Cause,-sum),sum,fill=Leading.Cause)) + | |
geom_bar(stat="identity") + guides(fill=guide_legend(title="Leading Cause")) + | |
scale_fill_discrete(breaks=c("Diseases of Heart (I00-I09, I11, I13, I20-I51)","Malignant Neoplasms (Cancer: C00-C97)","All Other Causes","Influenza (Flu) and Pneumonia (J09-J18)","Diabetes Mellitus (E10-E14)"))+ | |
xlab("Leading Cause") + ylab("Total Death") + | |
scale_x_discrete(labels=c("Diseases of Heart","Malignant Neoplasms","All Other Causes","Influenza (Flu) and Pneumonia","Diabetes Mellitus")) + | |
ggtitle("Top 5 Leading Causes of Death") + theme(plot.title = element_text(hjust = 0.5)) + 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