knitr::opts_chunk$set(echo = FALSE) library('vdhcovid') library('ggplot2') library('ggthemes') library('dplyr') plotdist <- function(district, yrng=NULL) { pltdata <- dplyr::filter(vaweeklytests, HealthDistrict==district) %>% group_by(week, date) %>% summarise(ntest=sum(ntest), npos=sum(npos), neff=sum(neff), nposeff=sum(nposeff)) %>% mutate(fpos=npos/ntest, fposeff=nposeff/neff) plt <- ggplot(pltdata, aes(x=date)) + geom_point(aes(y=fpos, color='nominal'), size=1.5) + geom_point(aes(y=fposeff, color='effective'), size=1.5, position=position_jitter(width=0, height=0.005)) + scale_color_solarized() + ylab('Positive test fraction') + labs(color='type', title=paste(district, 'Health District')) + theme_bw(14) if(is.null(yrng)) { plt } else { plt + coord_cartesian(ylim=yrng) } } testposcmp <- function(district=NA, mindate=as.Date('2020-07-01')) { testdata <- dplyr::select(vaweeklytests, HealthDistrict, date, ntest, npos, neff, nposeff) %>% dplyr::filter(date >= mindate) if(!is.na(district)) { testdata <- dplyr::filter(testdata, HealthDistrict == district) } testdata <- group_by(testdata, date) %>% summarise(ntest=sum(ntest), npos=sum(npos), neff=sum(neff), nposeff=sum(nposeff)) %>% mutate(fpos=npos/ntest, fposeff=nposeff/neff) rawd <- dplyr::select(testdata, date, ntest, fpos) %>% tidyr::pivot_longer(-date, names_to='var') %>% mutate(method = 'raw count') effd <- dplyr::select(testdata, date, neff, fposeff) %>% dplyr::rename(ntest=neff, fpos=fposeff) %>% tidyr::pivot_longer(-date, names_to='var') %>% mutate(method = 'effective count') pltdata <- dplyr::bind_rows(rawd, effd) ntraw <- testdata$ntest fpraw <- testdata$fpos rawcor <- cor(ntraw, fpraw, method='kendall') nteff <- testdata$neff fpeff <- testdata$fposeff effcor <- cor(nteff, fpeff, method='kendall') message('Raw correlation: ', signif(rawcor, 2)) message('Effective correlation: ', signif(effcor, 2)) if(is.na(district)) { titlestr = 'Statewide' } else { titlestr = paste(district, 'district') } ggplot(pltdata, aes(x=date, y=value, color=method)) + facet_wrap(~var, ncol=1, scales='free_y') + geom_line(size=1.2) + ggtitle(titlestr) + ylab('') + scale_color_solarized() + theme_bw() }
ptfstate <- dplyr::group_by(vaweeklytests, week, date) %>% summarise(ntest=sum(ntest), npos=sum(npos), neff=sum(neff), nposeff=sum(nposeff)) %>% mutate(fpos=npos/ntest, fposeff=nposeff/neff) ggplot(ptfstate, aes(x=date)) + geom_point(aes(y=fpos, color='nominal'), size=1.5) + geom_point(aes(y=fposeff, color='effective'), size=1.5, position=position_jitter(width=0, height=0.005)) + scale_color_solarized() + ylab('Positive test fraction') + coord_cartesian(ylim=c(0,0.25)) + labs(color='type', title='Commonwealth of Virginia') + theme_bw(14)
plotdist('Thomas Jefferson')
plotdist('Fairfax', c(0,0.4))
plotdist('Portsmouth')
ptfall <- group_by(vaweeklytests, week, date, HealthDistrict) %>% summarise(ntest=sum(ntest), npos=sum(npos), neff=sum(neff), nposeff=sum(nposeff)) %>% mutate(fpos=npos/ntest, fposeff=nposeff/neff) ggplot(ptfall, aes(x=date)) + geom_point(aes(y=fpos, color='nominal'), size=1.5) + geom_point(aes(y=fposeff, color='effective'), size=1.5, position=position_jitter(width=0, height=0.005)) + facet_wrap(~HealthDistrict, ncol=4, scales='free_y') + scale_color_solarized() + ylab('Positive test fraction') + labs(color='type', title='Positive test fractions by district') + #coord_cartesian(ylim=c(0,0.4)) + theme_bw(14)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.