diff --git a/README.Rmd b/README.Rmd
index e79cfb0..60b8f03 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -58,7 +58,7 @@ options(width=120)
### Usage
-```{r message=FALSE}
+```{r message=FALSE, warning=FALSE, fig.height=10, fig.width=6}
library(cdcfluview)
library(ggplot2)
library(dplyr)
@@ -77,9 +77,42 @@ gg <- ggplot(flu, aes(x=WEEK, y=`% WEIGHTED ILI`, group=REGION))
gg <- gg + geom_line()
gg <- gg + facet_wrap(~REGION, ncol=2)
gg <- gg + theme_bw()
+gg
```
-```{r echo=FALSE, fig.height=10, fig.width=6}
+```{r message=FALSE, warning=FALSE, fig.height=6, fig.width=10}
+msd <- get_mortality_surveillance_data()
+
+mutate(msd$by_state, ym=as.Date(sprintf("%04d-%02d-1", Year, Week), "%Y-%U-%u")) %>%
+ select(state, wk=ym, death_pct=`Percent of Deaths Due to Pneumonia and Influenza`) %>%
+ mutate(death_pct=death_pct/100) -> df
+
+gg <- ggplot() + geom_smooth(data=df, aes(wk, death_pct, group=state),
+ se=FALSE, color="#2b2b2b", size=0.25)
+
+gb <- ggplot_build(gg)
+
+gb$data[[1]] %>%
+ arrange(desc(x)) %>%
+ group_by(group) %>%
+ slice(1) %>%
+ ungroup() %>%
+ arrange(desc(y)) %>%
+ head(1) -> top
+
+top_state <- sort(unique(msd$by_state$state))[top$group]
+
+gg <- gg + geom_text(data=top, aes(as.Date(x, origin="1970-01-01"), y, label=top_state),
+ hjust=1, family="Arial Narrow", size=3, nudge_x=-5, nudge_y=-0.001)
+gg <- gg + scale_x_date(expand=c(0,0))
+gg <- gg + scale_y_continuous(label=scales::percent)
+gg <- gg + labs(x=NULL, y=NULL,
+ title="Percent of In-State Deaths Due to Pneumonia and Pnfluenza (2010-Present)")
+gg <- gg + theme_bw(base_family="Arial Narrow")
+gg <- gg + theme(axis.text.x=element_text(margin=margin(0,0,0,0)))
+gg <- gg + theme(axis.text.y=element_text(margin=margin(0,0,0,0)))
+gg <- gg + theme(axis.ticks=element_blank())
+gg <- gg + theme(plot.title=element_text(face="bold", size=16))
gg
```
@@ -129,11 +162,7 @@ gg <- gg + theme(axis.ticks.x=element_blank())
gg <- gg + theme(axis.text.x=element_blank())
```
-```{r echo=FALSE, fig.height=10, fig.width=6, warning=FALSE, error=FALSE, message=FALSE}
-gg
-```
-
-```{r message=FALSE}
+```{r message=FALSE, fig.height=5, fig.width=7}
gg_s <- state_flu %>%
filter(WEEKEND=="Jan-03-2015") %>%
select(state=STATENAME, value=ACTIVITY.LEVEL) %>%
@@ -143,9 +172,6 @@ gg_s <- state_flu %>%
labels=c("Minimal", "Low", "Moderate", "High"),
legend_position="bottom", legend_title="ILI Activity Level") +
ggtitle("CDC State FluView (2015-01-03)")
-```
-
-```{r echo=FALSE, fig.height=5, fig.width=7}
gg_s
```
diff --git a/README.md b/README.md
index 3827596..e143e28 100644
--- a/README.md
+++ b/README.md
@@ -88,11 +88,48 @@ gg <- ggplot(flu, aes(x=WEEK, y=`% WEIGHTED ILI`, group=REGION))
gg <- gg + geom_line()
gg <- gg + facet_wrap(~REGION, ncol=2)
gg <- gg + theme_bw()
+gg
```
-
+
-
+``` r
+msd <- get_mortality_surveillance_data()
+
+mutate(msd$by_state, ym=as.Date(sprintf("%04d-%02d-1", Year, Week), "%Y-%U-%u")) %>%
+ select(state, wk=ym, death_pct=`Percent of Deaths Due to Pneumonia and Influenza`) %>%
+ mutate(death_pct=death_pct/100) -> df
+
+gg <- ggplot() + geom_smooth(data=df, aes(wk, death_pct, group=state),
+ se=FALSE, color="#2b2b2b", size=0.25)
+
+gb <- ggplot_build(gg)
+
+gb$data[[1]] %>%
+ arrange(desc(x)) %>%
+ group_by(group) %>%
+ slice(1) %>%
+ ungroup() %>%
+ arrange(desc(y)) %>%
+ head(1) -> top
+
+top_state <- sort(unique(msd$by_state$state))[top$group]
+
+gg <- gg + geom_text(data=top, aes(as.Date(x, origin="1970-01-01"), y, label=top_state),
+ hjust=1, family="Arial Narrow", size=3, nudge_x=-5, nudge_y=-0.001)
+gg <- gg + scale_x_date(expand=c(0,0))
+gg <- gg + scale_y_continuous(label=scales::percent)
+gg <- gg + labs(x=NULL, y=NULL,
+ title="Percent of In-State Deaths Due to Pneumonia and Pnfluenza (2010-Present)")
+gg <- gg + theme_bw(base_family="Arial Narrow")
+gg <- gg + theme(axis.text.x=element_text(margin=margin(0,0,0,0)))
+gg <- gg + theme(axis.text.y=element_text(margin=margin(0,0,0,0)))
+gg <- gg + theme(axis.ticks=element_blank())
+gg <- gg + theme(plot.title=element_text(face="bold", size=16))
+gg
+```
+
+
``` r
gg_s <- state_flu %>%
@@ -104,9 +141,10 @@ gg_s <- state_flu %>%
labels=c("Minimal", "Low", "Moderate", "High"),
legend_position="bottom", legend_title="ILI Activity Level") +
ggtitle("CDC State FluView (2015-01-03)")
+gg_s
```
-
+
### Test Results
@@ -115,7 +153,7 @@ library(cdcfluview)
library(testthat)
date()
-#> [1] "Mon Sep 26 01:39:06 2016"
+#> [1] "Mon Sep 26 11:16:43 2016"
test_dir("tests/")
#> testthat results ========================================================================================================
diff --git a/README_files/README-unnamed-chunk-4-1.png b/README_files/README-unnamed-chunk-4-1.png
new file mode 100644
index 0000000..8978423
Binary files /dev/null and b/README_files/README-unnamed-chunk-4-1.png differ
diff --git a/README_files/README-unnamed-chunk-5-1.png b/README_files/README-unnamed-chunk-5-1.png
index 0e692dd..e1ca890 100644
Binary files a/README_files/README-unnamed-chunk-5-1.png and b/README_files/README-unnamed-chunk-5-1.png differ
diff --git a/README_files/README-unnamed-chunk-7-1.png b/README_files/README-unnamed-chunk-7-1.png
index 0e692dd..f13718d 100644
Binary files a/README_files/README-unnamed-chunk-7-1.png and b/README_files/README-unnamed-chunk-7-1.png differ