From 175d29695ef1b94dce40844a1ea1cc062f782500 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 28 Aug 2020 13:51:23 -0400 Subject: [PATCH] Add zoomed charts. --- rcode.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/rcode.go b/rcode.go index 2f7d6e8..9a1c7be 100644 --- a/rcode.go +++ b/rcode.go @@ -24,12 +24,26 @@ trate <- pivot_wider(totals, names_from='name') %>% transmute(date=date,county=c d2 <- rbind(queens, totals) -p1 <- ggplot(queens, aes(x=date, y=value, group=name, color=name))+geom_line(color='black',alpha=1/2)+scale_y_log10(n.breaks=6)+labs(y='',color='')+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom')+geom_smooth(method='gam',se=FALSE) -p2 <- ggplot(totals, aes(x=date, y=value, group=name, color=name))+geom_line(color='black',alpha=1/2)+scale_y_log10(n.breaks=6)+labs(y='')+labs(color='')+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom')+geom_smooth(method='gam',se=FALSE) +p1 <- ggplot(queens, aes(x=date, y=value, group=name, color=name))+geom_line(color='black',alpha=1/3)+scale_y_log10(n.breaks=6, position='right')+labs(y='',color='')+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom')+geom_smooth(se=FALSE,method='gam') +p2 <- ggplot(totals, aes(x=date, y=value, group=name, color=name))+geom_line(color='black',alpha=1/3)+stat_smooth(geom='line', linetype='dotted', method='gam', se=FALSE)+scale_y_log10(n.breaks=6, position='right')+labs(y='')+labs(color='')+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom')+geom_smooth(se=FALSE,method='gam') -pr1 <- ggplot(qrate, aes(x=date, y=value)) + geom_line(color='black',alpha=1/2)+geom_smooth(method='gam',formula=y~s(x, bs="cs"),se=FALSE)+scale_y_continuous(labels = scales::percent,)+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5)) -pr2 <- ggplot(trate, aes(x=date, y=value)) + geom_line(color='black',alpha=1/2)+geom_smooth(method='gam',formula=y~s(x, bs="cs"),se=FALSE)+scale_y_continuous(labels = scales::percent)+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5)) +pr1 <- ggplot(qrate, aes(x=date, y=value)) + geom_line(color='black',alpha=1/3)+geom_smooth(method='gam',formula=y~s(x, bs="cs"),se=FALSE)+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5)) +pr2 <- ggplot(trate, aes(x=date, y=value)) + geom_line(color='black',alpha=1/3)+geom_smooth(method='gam',formula=y~s(x, bs="cs"),se=FALSE)+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5)) -p <- grid.arrange(p1,p2,pr1,pr2,ncol=2,top=format(d[[nrow(d),1]], "%B %d %Y")) +queens <- tail(queens,n=16) +totals <- tail(totals,n=16) +qrate <- tail(qrate,n=8) +trate <- tail(trate,n=8) + +p3 <- ggplot(queens, aes(x=date, y=value, color=name))+geom_line()+scale_y_log10(n.breaks=12, position='right')+labs(y='',color='')+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom') +p4 <- ggplot(totals, aes(x=date, y=value, color=name))+geom_line()+scale_y_log10(n.breaks=12, position='right')+labs(y='')+labs(color='')+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5))+theme(legend.position='bottom') + +pr3 <- ggplot(qrate, aes(x=date, y=value)) + geom_line()+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('Queens')+theme(plot.title=element_text(hjust = 0.5)) + +pr4 <- ggplot(trate, aes(x=date, y=value)) + geom_line()+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5)) + +pdf(width=8,height=16) +grid.arrange(p1, p2, pr1, pr2, p3, p4, pr3, pr4, ncol=2, top=format(d[[nrow(d),1]], "%B %d %Y")) +dev.off() ` }