This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(shiny)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(rsconnect)
##
## Attaching package: 'rsconnect'
## The following object is masked from 'package:shiny':
##
## serverInfo
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
rsconnect::setAccountInfo(name='jagdish',
token='67A0CF780389C90C5917FDB0B2FBC52B',
secret='PZ3ApOsrebj7HeLZAGlYjZlu2o61XibdqoTF0Kmo')
head(cdc)
## ICD.Chapter State Year Deaths Population
## 1 Certain infectious and parasitic diseases AL 1999 1092 4430141
## 2 Certain infectious and parasitic diseases AL 2000 1188 4447100
## 3 Certain infectious and parasitic diseases AL 2001 1211 4467634
## 4 Certain infectious and parasitic diseases AL 2002 1215 4480089
## 5 Certain infectious and parasitic diseases AL 2003 1350 4503491
## 6 Certain infectious and parasitic diseases AL 2004 1251 4530729
## Crude.Rate
## 1 24.6
## 2 26.7
## 3 27.1
## 4 27.1
## 5 30.0
## 6 27.6
nrow(cdc)
## [1] 9961
cdc.2010<-cdc%>%filter(Year==2010 & ICD.Chapter == 'Certain infectious and parasitic diseases')%>%arrange(Crude.Rate)
nrow(cdc.2010)
## [1] 51
chart1<-ggplot(cdc.2010)+geom_bar(aes(x=reorder(State,Crude.Rate),y=Crude.Rate,fill=State),stat='identity')+coord_flip()+geom_text(aes(x=State,y=Crude.Rate,label=Crude.Rate),size=2, hjust=0, vjust=-0.2,position=position_dodge(.9))
chart1+ggtitle("Crude Mortality by State for 2010")+theme(axis.text.x = element_text(size=8, angle = 90, hjust = 1), axis.text.y = element_text(size=6), axis.title=element_text(size=14,face="bold")) + labs(title = 'Crude Mortality by State', x = 'State', y='Crude Mortality')
cdc.states<-cdc%>%select(ICD.Chapter,Year,Crude.Rate,State)
cdc.nation<-cdc%>%group_by(ICD.Chapter,Year)%>%summarize(Crude.Rate=(sum(Deaths)*100000/sum(Population)))%>%mutate(State='USA')
## `summarise()` regrouping output by 'ICD.Chapter' (override with `.groups` argument)
#cdc.nation$Crude.Rate<-as.numeric(cdc.nation$Crude.Rate)
cdc.nation$State<-as.factor(cdc.nation$State)
#str(cdc.nation$Crude.Rate)
#str(cdc.nation$State)
cdc.combined<-dplyr::bind_rows(cdc.states,cdc.nation)
cdc.combined.cause<-cdc.combined%>%filter(ICD.Chapter == 'Certain infectious and parasitic diseases')
nrow(cdc.combined.cause)
## [1] 624
cdc.combined.cause.state<-cdc.combined%>%filter(ICD.Chapter == 'Certain infectious and parasitic diseases' & (State=='USA'|State=='NY'))
nrow(cdc.combined.cause.state)
## [1] 24
plot_ly(cdc.combined.cause,x=~Year, y=~Crude.Rate,color = ~State, type='scatter', mode = 'lines')
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
chart2<-ggplot(cdc.combined.cause)+geom_line(aes(x=Year,y=Crude.Rate,color=State))#+geom_line(size=1.0)
chart3<-ggplot(cdc.combined.cause.state)+geom_line(aes(x=Year,y=Crude.Rate,color=State))
chart2+ggtitle( "Trend in mortality rate by State and National Average" )
chart2
chart3+ggtitle( "Trend in mortality rate by State and National Average" )
chart3