Skip to content

Instantly share code, notes, and snippets.

View quisqualis's full-sized avatar

Sanjay Mishra, PhD quisqualis

View GitHub Profile
@quisqualis
quisqualis / server.R
Created February 19, 2018 01:28 — forked from jcheng5/server.R
Shiny example: Diamonds Explorer
library(shiny)
library(ggplot2)
function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
library(tidyverse)
cases <- read_csv("https://api.coronavirus.data.gov.uk/v2/data?areaType=region&areaCode=E12000007&metric=newCasesBySpecimenDate&format=csv")
sgtf = read_csv("https://gist.githubusercontent.com/theosanderson/3443a0982d52283e6443f191a6a19d92/raw/118ec9dd4adb6f538c75b097ac0cc0ae66dcf655/LondonSGTF.csv", col_names = c("date","sgtf100")) %>% mutate(sgtf=sgtf100/100) %>% group_by(date) %>% summarise(sgtf=mean(sgtf))
both = full_join(cases,sgtf) %>% mutate(sgtf = ifelse(is.na(sgtf),0,sgtf),sgtf_cases = newCasesBySpecimenDate*sgtf,nonsgtf_cases = newCasesBySpecimenDate*(1-sgtf)) %>% select(date, sgtf_cases,nonsgtf_cases) %>% pivot_longer(-date) %>% mutate(variant=ifelse(name=="sgtf_cases","Omicron","Delta"))
both
ggplot(both %>% filter(date>"2021-6-1", date<="2021-12-11", date<= max(sgtf$date)),aes(x=date,color=variant,y=value))+geom_line() +theme_classic()+labs(x="Specimen date",y="Cases")+theme_bw()+scale_x_date(breaks=scales::pretty_breaks(6)) +scale_color_manual(values=c("#377eb8","#e41a1c",