About
=======================================================================
The Coronavirus Dashboard: the case of Ukraine
This Coronavirus dashboard: the case of Belgium provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Ukraine This dashboard is built with R using the R Makrdown framework and was adapted from this dashboard.
Code
The code behind this dashboard is available
Data
John Hopkins Institute
The data and dashboard are refreshed on a daily basis.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.
Update
The data is as of суббота май 09, 2020 and the dashboard has been updated on воскресенье май 10, 2020, las day update time 21:25 суббота май 09, 2020.
---
title: "Ukraine.COVID-19"
author: ""
output:
flexdashboard::flex_dashboard:
orientation: rows
# social: ["facebook", "twitter", "linkedin"]
source_code: embed
vertical_layout: fill
---
```{r setup1, include=FALSE}
#------------------ Libaries ------------------
source('D:/R/Work/functions_Covid.R')
source('D:/R/Work/Library_Constants.R')
library(flexdashboard)
library(data.table)
library(plotly)
library(maps)
library(rjson)
library(earlyR)
library(rvest)
library(deSolve)
library("wbstats")
library(covdata)
pop<-data.table(wb(indicator = c("SP.POP.TOTL"),mrv = 1))
pop[country=="United States"]$country<-'US'
pop[country=="Iran, Islamic Rep."]$country<-'Iran'
pop[country=="Korea, Rep."]$country<-"Korea, South"
pop[country=="Russian Federation"]$country<-"Russia"
pop[country=="Syrian Arab Republic"]$country <- "Syria"
pop[country=="Bahamas, The"]$country<-"Bahamas"
pop[country=="Brunei Darussalam"]$country<-"Brunei"
pop[country=="Congo, Dem. Rep."]$country<-"DR Congo"
pop[country=="Congo, Rep."]$country<-"Congo (Kinshasa)"
pop[country=="Czech Republic"]$country<-"Czechia"
pop[country=="Egypt, Arab Rep."]$country<-"Egypt"
#pop[country=="Kyrgyz Republic"]$country<-"Kyrgyzstan"
pop[country=="Slovak Republic"]$country<-"Slovakia"
url<-"https://covid19.com.ua/"
webpage <- read_html(url)
number_html <- html_nodes(webpage, "div")
number_html <-html_nodes(number_html[[22]],"div")
number_html <-html_nodes(number_html[[4]],"div")
s<-html_text(number_html)
s<-trimws(s)
s<-as.numeric(gsub(" ", "", s, fixed = TRUE))
test<-readRDS("D:/R/Work/test.rdf")
#test[13]$date<-as.Date("2020-04-25")
if (Sys.Date()%in%test$date){
test[date==Sys.Date()]$test=s
} else
{
test<-rbind(test,data.table(date=Sys.Date(),test=s))
}
saveRDS(test,"D:/R/Work/test.rdf")
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
tested_color <- "black"
#country_list<-c("US","Italy","Spain","Ukraine","France", "Canada","China")
jsonUP <- fromJSON(file ="https://api.covidnow.com/v1/global/countries",simplify=T)
x<-jsonUP[[1]][[1]]
countries<-attr(jsonUP[[1]],"names")
r<-lapply(jsonUP[[1]],function(x){
return(data.table(x$nationwide$update,x$nationwide$recovered,x$nationwide$confirmed,x$nationwide$deaths))
})
r<-rbindlist(r)
countries[countries=="UK"]<-"United Kingdom"
countries[countries=="South Korea"]<-"Korea, South"
countries[countries=="UAE"]<-"United Arab Emirates"
r$Counrty<-countries
names(r)<-c("ts","recovered","confirmed","death","Country/Region")
r[,date:=as.Date(as.POSIXlt(as.numeric(ts)/1000,origin="1970-01-01",tz="UTC"))]
r[is.na(date)]$date<-as.Date(as.POSIXlt(as.numeric(jsonUP[[2]])/1000,origin="1970-01-01",tz="UTC"))
#------------------ Data ------------------
ids<-c("Province/State","Country/Region","Lat","Long")
conf<-data.table(read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv",check.names = F))
conf<-melt(conf,id.vars = ids,measure.vars = names(conf)[!names(conf)%in%ids])
names(conf)<-c(ids,"date","confirmed")
conf$date<-as.Date(conf$date,"%m/%d/%y")
conf[confirmed<0,confirmed:=0]
dead<-data.table(read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv",check.names = F))
dead<-melt(dead,id.vars = ids,measure.vars = names(dead)[!names(dead)%in%ids])
names(dead)<-c(ids,"date","death")
dead$date<-as.Date(dead$date,"%m/%d/%y")
dead[death<0,death:=0]
recovered<-data.table(read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv",check.names = F))
names(recovered)[1]<-names(dead)[1]
recovered<-melt(recovered,id.vars = ids,measure.vars = names(recovered)[!names(recovered)%in%ids])
names(recovered)<-c(ids,"date","recovered")
recovered$date<-as.Date(recovered$date,"%m/%d/%y")
recovered[recovered<0,recovered:=0]
cor<-merge(conf,dead,by=c(ids,"date"),all.x = T,)
cor<-merge(cor,recovered,by=c(ids,"date"),all.x = T)
cor[is.na(recovered)]$recovered<-0
cor[is.na(death)]$death<-0
cor$`Country/Region`<-as.character(cor$`Country/Region`)
cor_ll<-cor
cor<-cor[,.(confirmed=sum(confirmed),recovered=sum(recovered),death=sum(death)),by=.(`Country/Region`,date) ]
if (max(cor[`Country/Region`=="Ukraine"]$confirmed)1000000]
ccountry_list[,conf:=round(conf/(value/1000000),2)][,death:=round(death/(value/1000000),2)]
setorder(ccountry_list,-conf)
ccountry_list_pm<-rbind(ccountry_list[1:10],ccountry_list[`Country/Region`=="Ukraine"])$`Country/Region`
df<-cor_U[nrow(cor_U)]
df$recovered<-max(cor_U$recovered)
df[,unrecovered:=confirmed-death-recovered]
df_daily<-cor_U[,.(date,confirmed,death,recovered)]
df_daily[,active_cum:=confirmed-death-recovered]
names(df_daily)<-c("date","confirmed_cum","death_cum","recovered_cum","active_cum")
cor_W<-cor[,.(confirmed=sum(confirmed),death=sum(death),recovered=sum(recovered)),by=.(date)]
df_W<-cor_W[nrow(cor_U)]
df_W$recovered<-max(cor_W$recovered)
df_W[,unrecovered:=confirmed-death-recovered]
df_daily_W<-cor_W[,.(date,confirmed,death,recovered)]
df_daily_W[,active_cum:=confirmed-death-recovered]
names(df_daily_W)<-c("date","confirmed_cum","death_cum","recovered_cum","active_cum")
#ggplot(cor_W,aes(date,recovered))+geom_point()
cor_U[,active:=confirmed-death-recovered]
cor<-merge(cor,pop[,.(country,value)],by.x = "Country/Region", by.y='country',all.x=T)
cor[,confirmed_pm:=round(confirmed/(value/1000000),2)]
cor[,death_pm:=round(death/(value/1000000),2)]
cor[,recovered_pm:=round(recovered/(value/1000000),2)]
mobility<-data.table(apple_mobility)
mobility[region=="Ukraine"]
#sort(unique(google_mobility$country_region))
```
Основные показатели.Украина
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### confirmed {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
caption = "Подтвержденные носители",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### active {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$unrecovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Активные носители (% of всех)", icon = "fas fa-ambulance",
color = active_color
)
```
### death {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Летальный исход (% от носителей)",
icon = "fas fa-heart-broken",
color = death_color
)
```
### recovered {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$recovered), big.mark = ","), " (",
round(100 * sum(df$recovered)/sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Вылечились (% от носителей)",
icon = "fas fa-heart-broken",
color = recovered_color
)
```
### tested {.value-box}
```{r}
valueBox(
value = paste(format(s, big.mark = ","), " (",
round(100 * sum(df$confirmed)/s, 1),
"%)",
sep = ""
),
caption = "Количество тестов (% носителей)",
icon = "fas fa-heart-broken",
color = death_color
)
```
Row
-----------------------------------------------------------------------
### **Динамика активных и летальных случаев** (Украина)
```{r}
plotly::plot_ly(data = df_daily[confirmed_cum>0]) %>%
plotly::add_trace(
x = ~date,
y = ~active_cum,
type = "scatter",
mode = "lines",
name = "Инфицированы",
fillcolor = active_color,
stackgroup = 'one'
) %>%
plotly::add_trace(
x = ~date,
y = ~recovered_cum,
type = "scatter",
mode = "lines",
name = "Вылечились",
fillcolor =recovered_color,
stackgroup = 'one'
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines",
name = "Летальные",
fillcolor =death_color,
stackgroup = 'one'
) %>%
plotly::add_trace(
x = ~date,
y = ~test,
type = "scatter",
mode = "lines+markers",
name = "Протестировано",
line = list(color = tested_color),
marker = list(color = tested_color),
data=test,
yaxis = "y2"
) %>%
plotly::add_annotations(
x = as.Date("2020-03-03"),
y = 1,
text = paste("Первый случай заражения"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-13"),
y = 1,
text = paste("Первый летальный"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -90,
ay = +10
) %>%
plotly::add_annotations(
x = as.Date("2020-03-25"),
y = 140,
text = paste("100 носителей"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -90,
ay = -10
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Кол-во инцидентов"),
xaxis = list(title = "Date"),
yaxis2 = list(overlaying = "y", side = "right",title="Количество тестов"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
Основные показатели.Мир
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### confirmed {.value-box}
```{r}
valueBox(
value = paste(format(sum(df_W$confirmed), big.mark = ","), "", sep = " "),
caption = "Подтвержденные носители",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### active {.value-box}
```{r}
valueBox(
value = paste(format(sum(df_W$unrecovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df_W$unrecovered, na.rm = TRUE) / sum(df_W$confirmed), 1),
"%)",
sep = ""
),
caption = "Активные носители (% of всех)", icon = "fas fa-ambulance",
color = active_color
)
```
### death {.value-box}
```{r}
valueBox(
value = paste(format(sum(df_W$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df_W$death, na.rm = TRUE) / sum(df_W$confirmed), 1),
"%)",
sep = ""
),
caption = "Летальный исход (% от носителей)",
icon = "fas fa-heart-broken",
color = death_color
)
```
### recovered {.value-box}
```{r}
valueBox(
value = paste(format(sum(df_W$recovered), big.mark = ","), " (",
round(100 * sum(df_W$recovered)/sum(df_W$confirmed), 1),
"%)",
sep = ""
),
caption = "Вылечились (% от носителей)",
icon = "fas fa-heart-broken",
color = recovered_color
)
```
### tested {.value-box}
```{r}
valueBox(
value = paste(format(s, big.mark = ","), " (",
round(100 * sum(df$confirmed)/s, 1),
"%)",
sep = ""
),
caption = "Количество тестов (% носителей)",
icon = "fas fa-heart-broken",
color = death_color
)
```
Row
-----------------------------------------------------------------------
### **Динамика активных и летальных случаев** (Украина)
```{r}
plotly::plot_ly(data = df_daily_W[confirmed_cum>0]) %>%
plotly::add_trace(
x = ~date,
y = ~active_cum,
type = "scatter",
mode = "lines+markers",
name = "Активные",
line = list(color = active_color),
marker = list(color = active_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines+markers",
name = "Летальные",
line = list(color = death_color),
marker = list(color = death_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~recovered_cum,
type = "scatter",
mode = "lines+markers",
name = "Вылечились",
line = list(color = recovered_color),
marker = list(color = recovered_color)
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Кол-во инцидентов"),
xaxis = list(title = "Date"),
yaxis2 = list(overlaying = "y", side = "right",title="Количество тестов"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
Сравнение по странам
=======================================================================
Column {data-width=400, .tabset}
------
### **Инциденты на 1 млн**
```{r}
daily_confirmed<-cor
setorder(daily_confirmed,`Country/Region`,date)
#----------------------------------------
# Plotting the data
Pr<- plot_ly(daily_confirmed)
Pr<-add_trace(Pr,
x = ~daily_confirmed[`Country/Region`=="Ukraine"]$date,
y = ~daily_confirmed[`Country/Region`=='Ukraine']$confirmed_pm,
type = "scatter",
mode = "lines",
name = 'Ukraine',
line = list( width = 4)
)
for (i in country_list){
pdata<-daily_confirmed[`Country/Region`%in%i]
Pr<-add_trace(Pr,
x = ~date,
y = ~confirmed_pm,
type = "scatter",
mode = "lines",
name = i,
data=pdata
)
}
Pr<-layout(Pr, title = "",legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
l = 60,
r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
### **Скороcть появления новых инцидентов**
```{r}
daily_confirmed<-cor
setorder(daily_confirmed,`Country/Region`,date)
daily_confirmed<-daily_confirmed[,confirmed_Speed:=confirmed-shift(confirmed, 1L, type="lag"),by=.(`Country/Region`)][is.na(confirmed_Speed)| confirmed_Speed<0,confirmed_Speed:=0]
daily_confirmed_W<-df_daily_W[,confirmed_Speed:=confirmed_cum-shift(confirmed_cum
, 1L, type="lag"),][is.na(confirmed_Speed)|confirmed_Speed<0,confirmed_Speed:=0]
#----------------------------------------
# Plotting the data
Pr<- plot_ly(daily_confirmed)
Pr <- add_trace(Pr,
x=~date,
y=~confirmed_Speed,
mode = "lines",
name = 'World',
line = list(width = 4,color="black"),
data=daily_confirmed_W,
yaxis = "y2")
Pr<-add_trace(Pr,
x = ~daily_confirmed[`Country/Region`=="Ukraine"]$date,
y = ~daily_confirmed[`Country/Region`=='Ukraine']$confirmed_Speed,
type = "scatter",
mode = "lines",
name = 'Ukraine',
line = list( width = 4)
)
for (i in country_list){
pdata<-daily_confirmed[`Country/Region`%in%i]
Pr<-add_trace(Pr,
x = ~date,
y = ~confirmed_Speed,
type = "scatter",
mode = "lines+markers",
name = i,
data=pdata
)
}
Pr<-layout(Pr, title = "",legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов"),
xaxis = list(title = "Date"),
yaxis2 = list(overlaying = "y", side = "right",title="Количество инцидентов. Мир"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
l = 60,
r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
### **Относительная скороcть появления новых инцидентов**
```{r}
daily_confirmed<-cor
setorder(daily_confirmed,`Country/Region`,date)
daily_confirmed<-daily_confirmed[confirmed>100,confirmed_Speed:=confirmed/shift(confirmed, 1L, type="lag")-1,by=.(`Country/Region`)][is.na(confirmed),confirmed:=0]
#----------------------------------------
# Plotting the data
Pr<- plot_ly(daily_confirmed)
Pr<-add_trace(Pr,
x = ~daily_confirmed[`Country/Region`=="Ukraine"]$date,
y = ~daily_confirmed[`Country/Region`=='Ukraine']$confirmed_Speed,
type = "scatter",
mode = "lines",
name = 'Ukraine',
line = list( width = 4)
)
for (i in country_list){
pdata<-daily_confirmed[`Country/Region`%in%i]
Pr<-add_trace(Pr,
x = ~date,
y = ~confirmed_Speed,
type = "scatter",
mode = "lines+markers",
name = i,
data=pdata
)
}
Pr<-layout(Pr, title = "",legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
Column {data-width=400, .tabset}
------
### **Количество инцидентов по странам на текущий момент**
```{r daily_summary}
df_world_last<-cor[,.(confirmed=max(confirmed),death=max(death),unrecovered=max(confirmed)-max(death)-max(recovered),
recovered=max(recovered),country=`Country/Region`),by=.(`Country/Region`)]
df_EU<-df_world_last[country%in%c(country_list,"Ukraine")]
df_EU$country<-as.character(df_EU$country)
df_EU<-df_EU[,.(unrecovered=sum(unrecovered),death=sum(death),recovered=sum(recovered),sorter=sum(recovered)+sum(unrecovered)+sum(death)),by=.(country)]
df_EU$country <- factor(df_EU$country, levels = unique(df_EU$country)[order(df_EU$sorter, decreasing = TRUE)])
plotly::plot_ly(
data = df_EU,
x = ~country,
y = ~unrecovered,
# text = ~ confirmed,
# textposition = 'auto',
type = "bar",
name = "Активные",
marker = list(color = active_color)
) %>%
plotly::add_trace(
y = ~death,
# text = ~ death,
# textposition = 'auto',
name = "Летальные",
marker = list(color = death_color)
) %>%
plotly::add_trace(
y = ~recovered,
# text = ~ death,
# textposition = 'auto',
name = "Выле",
marker = list(color = recovered_color)
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "Всего"),
xaxis = list(title = ""),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
Тренды
=======================================================================
Column {.tabset}
-------------------------------------
### **Подтвержденные. Логарифмические координаты**
```{r}
cummul<-cor
setorder(cummul,`Country/Region`,date)
cummul[,confirmed1:=confirmed-shift(confirmed, 1L, type="lag"),by=.(`Country/Region`)][is.na(confirmed1),confirmed1:=0]
cummul[,confirmed7:=Reduce(`+`, shift(confirmed1, 0:6, type="lag")),by=.(`Country/Region`)]
Pr<-plot_ly(cummul)
tdata<-cummul[`Country/Region`=='Ukraine'&confirmed>0]
tdata$day<-seq(1:nrow(tdata))
Pr<-add_trace(Pr,
x = ~day,
y = ~confirmed,
mode = "lines",
line = list(color = 'rgb(255, 0, 0)', width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list,"China")){
tdata<-cummul[`Country/Region`==i&confirmed>0]
tdata$day<-seq(1:nrow(tdata))
Pr<-add_trace(Pr,
x = ~day,
y = ~confirmed,
mode = "lines",
line = list(color = 'rgb(100, 100, 100)', width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
#legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов",type = "log"),
xaxis = list(title = "Дни"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
### **Заражение (отн. скорость)**
```{r}
cummul<-cor
setorder(cummul,`Country/Region`,date)
cummul[,confirmed1:=confirmed-shift(confirmed, 1L, type="lag"),by=.(`Country/Region`)][is.na(confirmed1),confirmed1:=0]
cummul[,confirmed7:=Reduce(`+`, shift(confirmed1, 0:6, type="lag")),by=.(`Country/Region`)]
Pr<-plot_ly(cummul)
tdata<-cummul[`Country/Region`=='Ukraine']
Pr<-add_trace(Pr,
x = ~confirmed,
y = ~confirmed7,
mode = "lines",
line = list(color = 'rgb(255, 0, 0)', width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list,"China")){
tdata<-cummul[`Country/Region`==i]
Pr<-add_trace(Pr,
x = ~confirmed,
y = ~confirmed7,
mode = "lines",
line = list(color = 'rgb(100, 100, 100)', width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов за последнюю неделю",type = "log"),
xaxis = list(title = "Количество инцидентов",type = "log"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
Column {.tabset}
----------------------------
### **Летальные. Логарифмические координаты**
```{r}
cummul<-cor
setorder(cummul,`Country/Region`,date)
cummul[,confirmed1:=confirmed-shift(confirmed, 1L, type="lag"),by=.(`Country/Region`)][is.na(confirmed1),confirmed1:=0]
cummul[,confirmed7:=Reduce(`+`, shift(confirmed1, 0:6, type="lag")),by=.(`Country/Region`)]
Pr<-plot_ly(cummul)
tdata<-cummul[`Country/Region`=='Ukraine'&death>0]
tdata$day<-seq(1:nrow(tdata))
Pr<-add_trace(Pr,
x = ~day,
y = ~death,
mode = "lines",
line = list(color = 'rgb(255, 0, 0)', width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list,"China")){
tdata<-cummul[`Country/Region`==i&death>0]
tdata$day<-seq(1:nrow(tdata))
Pr<-add_trace(Pr,
x = ~day,
y = ~death,
mode = "lines",
line = list(color = 'rgb(100, 100, 100)', width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
#legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов",type = "log"),
xaxis = list(title = "Дни"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
### **Смертность. (отн. скорость)**
```{r}
cummul<-cor
setorder(cummul,`Country/Region`,date)
cummul[,death1:=death-shift(death, 1L, type="lag"),by=.(`Country/Region`)][is.na(death),death:=0]
cummul[,death7:=Reduce(`+`, shift(death1, 0:6, type="lag")),by=.(`Country/Region`)]
Pr<-plot_ly(cummul)
tdata<-cummul[`Country/Region`=='Ukraine']
Pr<-add_trace(Pr,
x = ~death,
y = ~death7,
mode = "lines",
line = list(color = 'rgb(255, 0, 0)', width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list,"China")){
tdata<-cummul[`Country/Region`==i]
Pr<-add_trace(Pr,
x = ~death,
y = ~death7,
mode = "lines",
line = list(color = 'rgb(100, 100, 100)', width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Количество инцидентов за последнюю неделю",type = "log"),
xaxis = list(title = "Количество инцидентов",type = "log"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
Карта
=======================================================================
### **Количество инцидентов по странам** (*use + and - icons to zoom in/out*)
```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
df_world_last<-cor_ll[,.(confirmed=max(confirmed),death=max(death),unrecovered=max(confirmed)-max(death)-max(recovered),
recovered=max(recovered),country=`Country/Region`),by=.(`Country/Region`,`Province/State`,Lat,Long)]
cv_data_for_plot<-melt(df_world_last,c("Country/Region","Province/State","Lat",'Long'),measure.vars = c("confirmed", "death", "recovered"),variable.name = "type",value.name = "cases")[cases>1][,log_cases := 2 * log(cases)]
ge <- list(
showland = TRUE,
landcolor = toRGB("gray85"),
watercolor= toRGB("blue"),
countrywidth = 1,
countrycolor = toRGB("white")
)
plot_geo(cv_data_for_plot[`Province/State`==""]) %>%
add_markers(x = ~Long,
y = ~Lat,
color = ~type,
size=~log_cases,
colors = c(confirmed_color,death_color,recovered_color),
text=~paste(cases, type, `Country/Region`,sep=" "),
)%>%
layout(geo=ge)
```
Прогноз
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### U_estimate {.value-box}
```{r}
ues<-ExpDeadRate(cor_U$confirmed,cor_U$death)
valueBox(
value = paste(format(round(ues), big.mark = " "),"вместо", format(round(cor_U$confirmed[length(cor_U$confirmed)]), big.mark = " "), "", sep = " "),
caption = "Оценка количества зараженных на основании летальных исходов. Украина",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### W_estimate {.value-box}
```{r}
wes<-ExpDeadRate(cor_W$confirmed,cor_W$death)
valueBox(
value = paste(format(round(wes), big.mark = " "),"вместо", format(round(cor_W$confirmed[length(cor_W$confirmed)]), big.mark = " "), "", sep = " "),
caption = "Оценка количества зараженных на основании летальных исходов. Мир",
icon = "fas fa-user-md",
color = confirmed_color
)
```
Row
-----------------------------------------------------------------------
### **Прогноз на 10 дней (экспоненциальная экстраполяция). Украина**
```{r}
source('D:/R/Work/functions_Covid.R')
#plot(cfi(df_daily$active[df_daily$active!=0]))
#plot(growthRate(df_daily$active_cum[df_daily$active_cum!=0]))
t<-projSimple(cor_U[date!=Sys.Date()]$confirmed,cor_U[date!=Sys.Date()]$date)
#t %>%
# t
plotly::plot_ly() %>%
plotly::add_trace(
x = ~t$x,
y = ~t$y[,1],
type = "scatter",
mode = "markers",
name = "Прогноз"
) %>%
plotly::add_trace(
x = ~cor_U$date,
y = ~cor_U$confirmed,
type = "scatter",
mode = "lines",
name = "Факт"
) %>%
plotly::add_trace(
x = ~t$x,
y = ~t$y[,2],
type = "scatter",
mode = "markers",
name = "Нижний прогноз"
) %>%
plotly::add_trace(
x = ~t$x,
y = ~t$y[,3],
type = "scatter",
mode = "markers",
name = "Верхний прогноз"
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of new cases"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
### **Прогноз на 10 дней (экспоненциальная экстраполяция). Мир**
```{r}
tw<-projSimple(cor_W[date!=Sys.Date()]$confirmed,cor_W[date!=Sys.Date()]$date)
plotly::plot_ly() %>%
plotly::add_trace(
x = ~tw$x,
y = ~tw$y[,1],
type = "scatter",
mode = "markers",
name = "Прогноз"
) %>%
plotly::add_trace(
x = ~cor_W$date,
y = ~cor_W$confirmed,
type = "scatter",
mode = "lines",
name = "Факт"
) %>%
plotly::add_trace(
x = ~tw$x,
y = ~tw$y[,2],
type = "scatter",
mode = "markers",
name = "Нижний прогноз"
) %>%
plotly::add_trace(
x = ~tw$x,
y = ~tw$y[,3],
type = "scatter",
mode = "markers",
name = "Верхний прогноз"
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of new cases"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
ues1<-cor_U$confirmed/detRate(cor_U$confirmed,cor_U$death)
```
Модель Украина
===================
```{r}
get_SIR_max <- function(Active,dates,population) {
Infected<-Active
N <- population
init <- c(
S = N - Infected[1],
I = Infected[1],
R = 0
)
Day <- 1:(length(Infected))
RSS <- function(parameters) {
names(parameters) <- c("beta", "gamma")
out <- ode(y = init, times = Day, func = SIR, parms = parameters)
fit <- out[, 3]
sum((Infected - fit)^2)
}
SIR <- function(time, state, parameters) {
par <- as.list(c(state, parameters))
with(par, {
dS <- -beta * I * S / N
dI <- beta * I * S / N - gamma * I
dR <- gamma * I
list(c(dS, dI, dR))
})
}
Opt <- optim(c(0.5, 0.5),
RSS,
method = "L-BFGS-B",
lower = c(0, 0),
upper = c(1, 1)
)
sir_start_date <- min(dates)
Opt_par <- setNames(Opt$par, c("beta", "gamma"))
t <- 1:as.integer(Sys.Date() - ymd(sir_start_date))
fitted_cumulative_incidence <- data.frame(ode(
y = init, times = t,
func = SIR, parms = Opt_par
))
fitted_cumulative_incidence <- fitted_cumulative_incidence %>%
mutate(
Date = ymd(sir_start_date) + days(t - 1),
Country = "Ukraine",
cumulative_incident_cases = Infected
)
fittedmin<-fitted_cumulative_incidence
t <- 1:120
# get the fitted values from our SIR model
fitted_cumulative_incidence <- data.frame(ode(
y = init, times = t,
func = SIR, parms = Opt_par
))
R0<-Opt_par[1] / Opt_par[2]
# add a Date column and join the observed incidence data
fitted_cumulative_incidence <- fitted_cumulative_incidence %>%
mutate(
Date = ymd(sir_start_date) + days(t - 1),
Country = "Belgium",
cumulative_incident_cases = I
)
MaxI<-max(fitted_cumulative_incidence$I)
setNames(Opt$par, c("beta", "gamma"))
MaxT<-(sir_start_date+fitted_cumulative_incidence$time[fitted_cumulative_incidence$I==MaxI])
return(list(MaxI,MaxT,Opt$message, setNames(Opt$par, c("beta", "gamma")),R0 , fittedmin, fitted_cumulative_incidence))
}
CorA<-cor[date!=Sys.Date()]
CorA$Active<-CorA$confirmed-CorA$recovered-CorA$death
CorA$`Country/Region`<-as.character(CorA$`Country/Region`)
setorder(CorA,`Country/Region`,date)
x<-"Spain"
d<-as.Date("2020-02-26")
l<-lapply(unique(c(long_country_list[!long_country_list%in%c("Korea, South","Spain")],"Ukraine","Russia")), function(x){
#print(x)
resin<-get_SIR_max(CorA[date>d&`Country/Region`==x&Active>0]$Active,
CorA[date>d&`Country/Region`==x&Active>0]$date ,pop[country==x]$value)
#print(resin[[4]][1]/resin[[4]][2])
return(data.table(R_null=resin[[4]][1]/resin[[4]][2],Inf_max=resin[[1]],max_date=resin[[2]],country=x,model=resin[[3]]))
})
l<-rbindlist(l)
x<-"Ukraine"
ukr<-resin<-get_SIR_max(CorA[`Country/Region`==x&Active>0]$Active,
CorA[`Country/Region`==x&Active>0]$date ,pop[country==x]$value)
```
Row {data-width=400}
-----------------------------------------------------------------------
### R {.value-box}
```{r}
valueBox(
value = paste(format(ukr[[4]][1]/ukr[[4]][2], big.mark = ","),"", sep = " "),
caption = "Оценка R0. R0 — количество зараженных одним инфицированным.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Date {.value-box}
```{r}
valueBox(
value = paste(format(l[country=="Ukraine"]$max_date[1], big.mark = ","),"", sep = " "),caption = "Дата максимального количества зараженных.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Max {.value-box}
```{r}
valueBox(
value = paste(format(l[country=="Ukraine"]$Inf_max[1], big.mark = ","),"", sep = " "),caption = "Максимальное количество зараженных одновременно.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
Column {data-width=400}
-----------------------------------------------------------------------
### Chart 1
```{r}
fittedmin<-ukr[[6]]
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~active,
type = "scatter",
mode = "markers",
name = "Факт",
data=cor_U
) %>%
plotly::add_trace(
x = ~Date,
y = ~I,
type = "scatter",
mode = "lines",
name = "Прогноз",
data=fittedmin
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of new cases"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
### Chart 1
```{r}
fitted_max<-ukr[[7]]
inf<-data.table(Infect=cor_U[date!=Sys.Date()]$confirmed,date=fitted_max$Date[1:length(cor_U[date!=Sys.Date()]$confirmed)])
fitted_max%>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~active,
type = "scatter",
mode = "markers",
name = "Факт",
data=cor_U
) %>%
plotly::add_trace(
x = ~Date,
y = ~I,
type = "scatter",
mode = "lines",
name = "Прогноз Инфицированные",
data=fitted_max
) %>%
plotly::add_trace(
x = ~Date,
y = ~R,
type = "scatter",
mode = "lines",
name = "Прогноз Восстановленные",
data=fitted_max
) %>%
plotly::add_trace(
x = ~Date,
y = ~S,
type = "scatter",
mode = "lines",
name = "Прогноз Не болели",
data=fitted_max
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of new cases"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
Модель Мир
=======
```{r}
library(DT)
datatable(l,options = list(pageLength = 100))
```
Логистическая
=======
Row {data-width=400}
-----------------------------------------------------------------------
```{r}
y2<-cor_U[confirmed>0]$confirmed
x2<-1:nrow(cor_U[confirmed>0])
data<-data.table(x2,y2)
logik<-function(par,x1){
a <- par[1]
b <- par[2]
c <- par[3]
p <-a/(1+exp(-b*(x1-c)))
return(p)
}
RSS <- function(par,data) {
return(sum((data$y-logik(par,data$x))^2))
}
Opt<-optim(par=c(00,00,00),method = "L-BFGS-B",
lower = c(-0, 0,0),
upper = c(1000000, 1000000,1000000), fn=RSS,data=data)
par<-Opt$par
sir_start_date <- 1
near<-data.table(t= 1:length(cor_U[confirmed>0]$date),date=cor_U[confirmed>0]$date)
near[,y1:=logik(Opt$par,t)]
near$y2<-y2
#ggplot(near,aes(t,y1))+geom_point()+geom_point(aes(t,y2))
long<-data.table(t= 1:1000, date=seq(from=cor_U[confirmed>0]$date[1],by=1,len=1000))
long[,y1:=logik(Opt$par,t)]
long[,dy1:=y1-shift(y1,1L,"lag")]
long<-long[!is.na(dy1)&dy1>1]
#ggplot(long,aes(date,y1))+geom_point()
```
### Date_l {.value-box}
```{r}
valueBox(
value = paste(format(long$date[nrow(long)], big.mark = ","),"", sep = " "),caption = "Дата максимального количества зараженных.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Max_L {.value-box}
```{r}
valueBox(
value = paste(format(round(long$y1[nrow(long)],0), big.mark = ","),"", sep = " "),caption = "Максимальное количество зараженных одновременно.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
Column {data-width=400}
-----------------------------------------------------------------------
### Chart 1
```{r}
Pr<-plot_ly(near)
Pr<-add_trace(Pr,
x = ~date,
y = ~y2,
type = "scatter",
mode = "markers",
name = "Факт",
data=near
)
Pr<-add_trace(Pr,
x = ~date,
y = ~y1,
type = "scatter",
mode = "lines",
name = "Прогноз",
data=long
)
Pr<-layout(Pr,
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of new cases"),
xaxis = list(title = "Date"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
About
Условия Кабмина
=======
```{r}
daily_confirmed<-cor
setorder(daily_confirmed,`Country/Region`,date)
daily_confirmed<-daily_confirmed[,confirmed_Speed:=confirmed-shift(confirmed, 1L, type="lag"),by=.(`Country/Region`)][is.na(confirmed_Speed),confirmed_Speed:=0]
daily_confirmed<-daily_confirmed[,rec_Speed:=recovered-shift(recovered, 1L, type="lag"),by=.(`Country/Region`)][is.na(rec_Speed),rec_Speed:=0]
daily_confirmed<-merge(daily_confirmed[`Country/Region`=="Ukraine"],test,by="date",all.x=T)[!is.na(test)]
daily_confirmed<-daily_confirmed[,test_Speed:=test-shift(test, 1L, type="lag"),by=.(`Country/Region`)][is.na(test_Speed),test_Speed:=0]
daily_confirmed[test_Speed>0,test_perc:=confirmed_Speed/test_Speed*100]
```
Row {data-width=400}
-----------------------------------------------------------------------
### Last {.value-box}
```{r}
valueBox(
value = paste(format(sum(tail(daily_confirmed,1)$confirmed_Speed)/sum(tail(daily_confirmed,1)$test_Speed)*100, big.mark = ","),"", sep = " "),
caption = "Процент положительніх тестов за последний день.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Ten {.value-box}
```{r}
valueBox(
value = paste(format(sum(tail(daily_confirmed,10)$confirmed_Speed)/sum(tail(daily_confirmed,10)$test_Speed)*100, big.mark = ","),"", sep = " "),
caption = "Средний процент положительных тестов за 10 дней.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Ten {.value-box}
```{r}
valueBox(
value = paste(format(sum(daily_confirmed$confirmed_Speed)/sum(daily_confirmed$test_Speed)*100, big.mark = ","),"", sep = " "),
caption = "Средний процент положительніх тестов за весь период.",
icon = "fas fa-user-md",
color = confirmed_color
)
```
Column {.tabset}
----------------------------
### **Процент выявленных от тестов**
```{r}
plotly::plot_ly(
data = daily_confirmed,
x = ~date,
y = ~test_perc,
text = ~ test_perc,
textposition = 'auto',
type = "bar",
name = "Процент положительных тестов",
color = active_color
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "%"),
xaxis = list(title = ""),
hovermode = "group",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
### **Рост заболевших/выздоровевших**
```{r}
plot_ly(data=daily_confirmed)%>%
add_trace(
x = ~date,
y = ~-confirmed_Speed,
type = "bar",
name = "Инфицировались",
marker = list(color = death_color,width=1)
) %>%
add_trace(
x = ~date,
y = ~rec_Speed,
type = "bar",
name = "Вылечились",
marker = list(color = recovered_color,width=1)
)%>%
add_trace(
x = ~date,
y = ~rec_Speed-confirmed_Speed,
type = "scatter",
mode = "lines",
name = "Баланс",
marker = list(color = confirmed_color,width=2)
)%>%
plotly::layout(
barmode = "group",
yaxis = list(title = "%"),
xaxis = list(title = ""),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
Мобильность
=======
Column {.tabset}
----------------------------
### **Пешеходы**
```{r}
mob_walk<-mobility[transportation_type=="walking"]
setorder(mob_walk,region,date)
Pr<-plot_ly(mob_walk)
tdata<-mob_walk[`region`=='Ukraine']
Pr<-add_trace(Pr,
x = ~date,
y = ~index,
mode = "lines",
line = list( width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list)){
tdata<-mob_walk[`region`==i]
Pr<-add_trace(Pr,
x = ~date,
y = ~index,
mode = "lines",
line = list( width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Index, Apple"),
xaxis = list(title = "Дата"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
### **Водители**
```{r}
mob_walk<-mobility[transportation_type=="driving"]
setorder(mob_walk,region,date)
Pr<-plot_ly(mob_walk)
tdata<-mob_walk[`region`=='Ukraine']
Pr<-add_trace(Pr,
x = ~date,
y = ~index,
mode = "lines",
line = list( width = 4),
name = "Ukraine",
data=tdata
)
for (i in c(country_list)){
tdata<-mob_walk[`region`==i]
Pr<-add_trace(Pr,
x = ~date,
y = ~index,
mode = "lines",
line = list( width = 1),
name = i,
data=tdata
)
}
Pr<-layout(Pr,
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Index, Apple"),
xaxis = list(title = "Дата"),
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
Pr
```
=======================================================================
**The Coronavirus Dashboard: the case of Ukraine**
This Coronavirus dashboard: the case of Belgium provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Ukraine This dashboard is built with R using the R Makrdown framework and was adapted from this [dashboard](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"}.
**Code**
The code behind this dashboard is available
**Data**
John Hopkins Institute
```
```
The data and dashboard are refreshed on a daily basis.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/CSSEGISandData/COVID-19){target="_blank"}.
**Update**
The data is as of `r format(max(cor$date), "%A %B %d, %Y")` and the dashboard has been updated on `r format(Sys.time(), "%A %B %d, %Y")`, las day update time `r format(as.POSIXlt(as.numeric(jsonUP[[2]])/1000,origin="1970-01-01",tz="UTC"), "%H:%M %A %B %d, %Y")`.