Column

Total

Row

confirmed

6,460,758

Recovered

2,089,694

death

238,562 (3.7%)

Column

Death In top 5 country

Row

Death Cases

Conformed cases in Top 5 country

Confirmed Cases

Death and conformed cases ratio

compraison

---
title: "Coronavirus"
author: "Krishna Kumar Shrestha"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    # social: ["facebook", "twitter", "linkedin"]
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(tidyverse)

library(reshape2)

confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
library(readr)
confirmedCases <- read_csv("C:/Users/User/Downloads/time_series_covid19_confirmed_global.csv")
deathCases <- read_csv("C:/Users/User/Downloads/time_series_covid19_deaths_global.csv")

recoveredCases <- read_csv("C:/Users/User/Downloads/time_series_covid19_recovered_global.csv")
confirmedCases<-confirmedCases%>%select(-c(Lat,Long))%>%melt(id=c('Country/Region','Province/State'))

confirmedCases<-confirmedCases%>%group_by(`Country/Region`,variable)%>%summarise(Confirmed=sum(value))

deathCases<-deathCases%>%select(-c(Lat,Long))%>%melt(id=c('Country/Region','Province/State'))
deathCases<-deathCases%>%group_by(`Country/Region`,variable)%>%summarise(Deaths=sum(value))

recoveredCases<-recoveredCases%>%select(-c(Lat,Long))%>%melt(id=c('Country/Region','Province/State'))
recoveredCases<-recoveredCases%>%group_by(`Country/Region`,variable)%>%summarise(Recovered=sum(value))


# rename table columns
colnames(confirmedCases)<-c("Country","Date","Confirmed")
colnames(deathCases)<-c("Country","Date","Death")
colnames(recoveredCases)<-c("Country","Date","Recovered")



```

Column {data-width=650}
-----------------------------------------------------------------------

Total
=======================================================================

Row {data-width=400}
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}
valueBox(
  value = paste(format(sum(confirmedCases$Confirmed), big.mark = ","), "", sep = " "),
  caption = "Total confirmed cases",
  icon = "fas fa-user-md",
  color = confirmed_color
)
```


### Recovered {.value-box}

```{r}
valueBox(
  value = paste(format(sum(recoveredCases$Recovered), big.mark = ","), "", sep = " "),
  caption = "Total recovered cases",
  icon = "fas fa-user-md",
  color = recovered_color
)
```
















### death {.value-box}

```{r}
valueBox(
  value = paste(format(sum(deathCases$Death, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(deathCases$Death, na.rm = TRUE) / sum(confirmedCases$Confirmed), 1),
    "%)",
    sep = ""
  ),
  caption = "Death cases (death rate)",
  icon = "fas fa-heart-broken",
  color = death_color
)
```


Column {data-width=650}
-----------------------------------------------------------------------
Death In top 5 country
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------


### Death Cases

```{r}
df1<-deathCases %>% dplyr::group_by(Date, Country) %>%
  dplyr::summarise(total = sum(Death)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = Country, values_from = total)

#----------------------------------------
# Plotting the data

df1 %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~Date,
    y = ~US,
    type = "scatter",
    mode = "lines+markers",
    name = "USA"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~France,
    type = "scatter",
    mode = "lines+markers",
    name = "France"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~Spain,
    type = "scatter",
    mode = "lines+markers",
    name = "Spain"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~Italy,
    type = "scatter",
    mode = "lines+markers",
    name = "Italy"
  ) %>%  plotly::add_trace(
    x = ~Date,
    y = ~China,
    type = "scatter",
    mode = "lines+markers",
    name = "China"
  ) %>%  plotly::add_trace(
    x = ~Date,
    y = ~Iran,
    type = "scatter",
    mode = "lines+markers",
    name = "Iran"
  ) %>%
  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
    )
  )
```

Conformed cases in Top 5 country
=======================================================================
### Confirmed Cases

```{r}
df<-confirmedCases %>% dplyr::group_by(Date, Country) %>%
  dplyr::summarise(total = sum(Confirmed)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = Country, values_from = total)

#----------------------------------------
# Plotting the data

df %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~Date,
    y = ~US,
    type = "scatter",
    mode = "lines+markers",
    name = "USA"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~France,
    type = "scatter",
    mode = "lines+markers",
    name = "France"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~Spain,
    type = "scatter",
    mode = "lines+markers",
    name = "Spain"
  ) %>%
  plotly::add_trace(
    x = ~Date,
    y = ~Italy,
    type = "scatter",
    mode = "lines+markers",
    name = "Italy"
  ) %>%  plotly::add_trace(
    x = ~Date,
    y = ~China,
    type = "scatter",
    mode = "lines+markers",
    name = "China"
  ) %>%  plotly::add_trace(
    x = ~Date,
    y = ~Iran,
    type = "scatter",
    mode = "lines+markers",
    name = "Iran"
  ) %>%
  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
    )
  )
```




Death and conformed cases ratio
=======================================================================   

### compraison


```{r}
merged<-merge(confirmedCases,deathCases,by.y = c("Country","Date"))

merged$Date<-as.Date(merged$Date,"%m/%d/%y")

df_EU <- merged %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(Country == "US" |
    Country == "France" |
    Country == "Italy" |
    Country == "Spain" |
      Country == "China" |
      Country=="Iran") %>% dplyr::filter(Date == max(Date))

plotly::plot_ly(
  data = df_EU,
  x = ~Country,
  # y = ~unrecovered,
  y = ~ Confirmed,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Confirmed",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~Death,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Death",
    marker = list(color = death_color)
  ) %>%
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total cases"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )


```