Countries ~ By WHO Region

Row

Countries has WHO_region:

Country doesnot have WHO_region

Covid19 statistics

Row

Covid statistics Results:

Covid19 Total Cases

Row

Country with respect to maximum & minimum[Excluding 0] Total Covid Cases:

Top 10 Countries gives maximum Total Covid Cases:

Top 10 Countries gives minimum Total Covid Cases- Excluding 0:

Covid19 New Cases

Row

Country with respect to maximum & minimum[Excluding 0] New Cases:

Top 10 Countries gives maximum New Cases:

Top 10 Countries gives minimum New Cases- Excluding 0:

Covid19 Death Cases

Row

Country with respect to maximum & minimum[Excluding 0] New Deaths:

Top 10 Countries gives maximum New Deaths:

Top 10 Countries gives minimum New Deaths - Excluding 0:

COVID-19 Cases ~ By Years

Row

Total Deaths Over the Years

Total New Cases Over the Years

Overall Cases Over the Years

COVID-19 Max/Min Cases ~ By Years

Row

Max/Min Deaths Occurred by Year

Max/Min New Cases Occurred by Years

Max/Min Overall Cases Occurred by Year

COVID-19 Deaths Cases ~ By Date

Row

Max/Min Deaths Occurred by Dates

Tracking the Peak COVID-19 Death Rates

Tracking the Bottom COVID-19 Death Rates

COVID-19 New Cases ~ By Date

Row

Max/Min New Cases Occurred by Dates

Tracking the Peak COVID-19 New Cases Rates

Tracking the Bottom COVID-19 New Case Rates

Max cumulative cases/deaths ~ By country, date-reported

Row

Maximum cumulative deaths by each country by date-reported

Maximum cumulative cases by each country by date-reported

---
title: "Covid-19 Analysis Dashboard"
author: "Dharshini Balasundaram"
date: "2025-01-02"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
setwd("C:/Users/dhars/Downloads/Dhass/codeing/PowerBI/PowerBi Main Course/Step 6/1. DataSets/R Programming Datasets")
getwd()
covid<-read.csv("WHO-COVID-19-global-data.csv")
covid
attach(covid)
library(dplyr)
library(plotly)
library("ggplot2")
library(corrplot)
library(scatterplot3d)
library(carData)
library(plotrix)
palette()
```

Countries ~ By WHO Region
=======================================================================
Row
-----------------------------------------------------------------------
### Countries has WHO_region:

```{r}
#How many Countries has WHO_region:
Count_WHO_regions_countriesOnly = covid%>% 
  select(WHO_region,Country)%>% 
  group_by(WHO_region)%>% 
  summarize(No.Of.Countries = n_distinct(Country))%>% 
  filter(WHO_region != "")

plot_ly(data = Count_WHO_regions_countriesOnly,
        x = ~WHO_region,          y = ~No.Of.Countries,
        color = ~No.Of.Countries,      type = "scatter",
        mode = "markers+text", 
        text = ~No.Of.Countries,
        textposition = "top middle") %>% 
  layout(title = "WHO Regions vs. Number of Countries", 
         xaxis = list(title = "WHO Region"), 
         yaxis = list(title = "Number of Countries"))
```

### Country doesnot have WHO_region
```{r}
#How many Country doesnot have WHO_region:
Count_Of_Countries_Doesnot_have_WHO_regions = covid%>% 
  select(WHO_region,Country)%>% 
  group_by(WHO_region)%>% 
  summarize(No.Of.Countries = n_distinct(Country))%>% 
  filter(WHO_region == "")

plott = plot_ly(data = Count_Of_Countries_Doesnot_have_WHO_regions, 
                x = ~WHO_region, 
                y = ~No.Of.Countries, 
                color = ~No.Of.Countries, type = "bar",
                text = ~No.Of.Countries,
                textposition = "inside", 
                textfont = list(color = "black")) %>% 
  layout(title = "Countries doesnot have WHO_region", 
         xaxis = list(title = "WHO Region"), 
         yaxis = list(title = "Number of Countries"))
plott
```


Covid19 statistics
=======================================================================
Row
-----------------------------------------------------------------------
### Covid statistics Results:
```{r}
#Total New Cases:
Total_New_Cases = sum(covid$New_cases, na.rm = TRUE)

#Total New Deaths:
Total_New_Deaths = sum(covid$New_deaths, na.rm = TRUE)

#Total Covid Cases:
Total_Covid_Cases = Total_New_Cases + Total_New_Deaths


#Total combined results:
Total_Results = c(Total.Covid.Cases = Total_Covid_Cases,Total.New.Deaths = Total_New_Deaths,Total.New.Cases = Total_New_Cases)

sorted_Total_Results <- Total_Results[order(Total_Results, decreasing = TRUE)]

barplot(sorted_Total_Results, col = heat.colors(3),main = "COVID-19 statistics"
        , xlab = "Covid Statistics", ylab = "Values") 
legend(x = "topright", legend = c(sorted_Total_Results) ,
       col = heat.colors(3), pch = 16, bty = "o", title = "Total_Results")
```





Covid19 Total Cases
=======================================================================
Row
-----------------------------------------------------------------------
### Country with respect to maximum & minimum[Excluding 0] Total Covid Cases:
```{r}
covid <- covid %>% mutate(Total_Covid_Cases = New_cases + New_deaths) 

#Which country gives maximum & minimum Total Cases:
#Which county gives maximum Total Cases:
Maximum_Total_Cases = covid %>% select(Country,Total_Covid_Cases)%>% group_by(Country) %>% 
  summarise(Total_Cases = sum(Total_Covid_Cases, na.rm = TRUE))%>% 
  filter(Total_Cases == max(Total_Cases, na.rm = TRUE))

#Which county gives minimum Total Cases[Excluding 0]:
Minimum_Total_Cases = covid %>% select(Country,Total_Covid_Cases)%>% group_by(Country) %>% 
  summarise(Total_Cases = sum(Total_Covid_Cases, na.rm = TRUE))%>%  
  filter(Total_Cases > 0) %>% filter(Total_Cases == min(Total_Cases, na.rm = TRUE)) 


Countries_with_MaxMin_TotalCases_Occured = rbind(Maximum_Total_Cases,Minimum_Total_Cases)

bar_heights10 = barplot(Countries_with_MaxMin_TotalCases_Occured$Total_Cases, 
                        names.arg = Countries_with_MaxMin_TotalCases_Occured$Country, 
                        main = "Max/Min Overall Cases Occurred by Country", 
                        xlab = "Country", 
                        ylab = "Over All Cases", 
                        col = terrain.colors(length(Country)),
                        las = 1/2)
text(x = bar_heights10, y = Countries_with_MaxMin_TotalCases_Occured$Total_Cases/2, 
     labels = Countries_with_MaxMin_TotalCases_Occured$Total_Cases, 
     pos = 2, cex = 0.5, col = "black")


```


### Top 10 Countries gives maximum Total Covid Cases:
```{r}
#Top 10 Countries gives maximum Total Cases:
Top10_Countries_Total_Cases = covid %>% select(Country,Total_Covid_Cases)%>% group_by(Country) %>% 
  summarise(Total_Cases = sum(Total_Covid_Cases, na.rm = TRUE))%>%
  arrange(desc(Total_Cases)) %>% slice(1:10)

countries4 <- Top10_Countries_Total_Cases$Country
new_cases4 <- Top10_Countries_Total_Cases$Total_Cases

bar_heights11 <- barplot(new_cases4, names.arg = countries4, col = terrain.colors(length(new_cases4)), 
                         las = 3, cex.names = 0.8, main = "Top 10 Countries by New COVID-19 Over All Cases", 
                         xlab = "Countries", ylab = "Total Cases")

text(x = bar_heights11, y = new_cases4/2, labels = new_cases4, pos = 1, cex = 0.5, col = "black")
```





### Top 10 Countries gives minimum Total Covid Cases- Excluding 0:
```{r}
#Bottom 10 Countries gives minimum Total Cases:
Bottom10_Countries_Total_Cases = covid %>% select(Country,Total_Covid_Cases)%>% group_by(Country) %>% 
  summarise(Total_Cases = sum(Total_Covid_Cases, na.rm = TRUE))%>%
  arrange(Total_Cases) %>% slice(1:10)%>%  
  filter(Total_Cases > 0)

countries5 <- Bottom10_Countries_Total_Cases$Country
new_cases5 <- Bottom10_Countries_Total_Cases$Total_Cases

bar_heights12 <- barplot(new_cases5, names.arg = countries5, col = terrain.colors(length(new_cases5)), 
                         las = 3, cex.names = 0.8, main = "Bottom 10 Countries by New COVID-19 Over All Cases", 
                         xlab = "Countries", ylab = "Total Cases")

text(x = bar_heights12, y = new_cases5/2, labels = new_cases5, pos = 2, cex = 0.5, col = "black")
```







Covid19 New Cases
=======================================================================
Row
-----------------------------------------------------------------------
### Country with respect to maximum & minimum[Excluding 0] New Cases:
```{r}
#Which county gives maximum & minimum New Cases:
#Which county gives maximum New Cases:
Maximum_New_Cases = covid %>% select(Country, New_cases) %>% group_by(Country)  %>%
  summarise(Total_New_Cases = sum(New_cases, na.rm = TRUE)) %>% filter(Total_New_Cases == max(Total_New_Cases, na.rm = TRUE))

#Which county gives minimum New Cases:
Minimum_New_Cases = covid %>% select(Country, New_cases) %>% group_by(Country)  %>%
  summarise(Total_New_Cases = sum(New_cases, na.rm = TRUE)) %>% filter(Total_New_Cases > 0) %>% filter(Total_New_Cases == min(Total_New_Cases, na.rm = TRUE))

Countries_with_MaxMin_NewCases_Occured = rbind(Maximum_New_Cases,Minimum_New_Cases)

bar_heights10 = barplot(Countries_with_MaxMin_NewCases_Occured$Total_New_Cases, 
                        names.arg = Countries_with_MaxMin_NewCases_Occured$Country, 
                        main = "Max/Min Cases Occurred by Country", 
                        xlab = "Country", 
                        ylab = "Total New Cases", 
                        col = terrain.colors(length(Country)), 
                        las = 1/2)
text(x = bar_heights10, y = Countries_with_MaxMin_NewCases_Occured$Total_New_Cases/2, 
     labels = Countries_with_MaxMin_NewCases_Occured$Total_New_Cases, 
     pos = 2, cex = 0.7, col = "black")

```


### Top 10 Countries gives maximum New Cases:
```{r}
#Top 10 Countries gives maximum New Cases:
Top10_Countries_New_Cases = covid %>% select(Country, New_cases) %>% group_by(Country)  %>% summarise(Total_New_Cases = sum(New_cases, na.rm = TRUE)) %>% arrange(desc(Total_New_Cases)) %>% slice(1:10)

# Separate country names and new case counts
countries <- Top10_Countries_New_Cases$Country
new_cases <- Top10_Countries_New_Cases$Total_New_Cases

# Create the bar plot and store the bar heights
bar_heights <- barplot(new_cases, names.arg = countries, col = terrain.colors(length(new_cases)), 
                       las = 3, cex.names = 0.8, main = "Top 10 Countries by New COVID-19 Cases", 
                       xlab = "Countries", ylab = "Total New Cases")

# Add the new cases values on top of each bar
text(x = bar_heights, y = new_cases/2, labels = new_cases, pos = 1, cex = 0.5, col = "black")


```

### Top 10 Countries gives minimum New Cases- Excluding 0:
```{r}
#Bottom 10 Countries gives minimum New Cases:
Bottom10_Countries_New_Cases = covid %>% select(Country, New_cases) %>% group_by(Country)  %>% 
  summarise(Total_New_Cases = sum(New_cases, na.rm = TRUE)) %>% arrange((Total_New_Cases)) %>% slice(1:10)%>%  
  filter(Total_New_Cases > 0)

countries1 <- Bottom10_Countries_New_Cases$Country
new_cases1 <- Bottom10_Countries_New_Cases$Total_New_Cases

# Create the bar plot and store the bar heights
bar_heights1 <- barplot(new_cases1, names.arg = countries1, col = terrain.colors(length(new_cases1)), 
                        las = 3, cex.names = 0.8, main = "Bottom 10 Countries by New COVID-19 Cases", 
                        xlab = "Countries", ylab = "Total New Cases")

# Add the new cases values on top of each bar
text(x = bar_heights1, y = new_cases1/2, labels = new_cases1, pos = 3, cex = 0.5, col = "black")
```




Covid19 Death Cases
=======================================================================
Row
-----------------------------------------------------------------------
### Country with respect to maximum & minimum[Excluding 0] New Deaths:
```{r}
#Which county gives maximum and minimum New Deaths:
#Which county gives maximum New Deaths:
Maximum_New_deaths = covid %>% select(Country, New_deaths) %>% group_by(Country)  %>%
  summarise(Total_New_Deaths = sum(New_deaths, na.rm = TRUE)) %>% filter(Total_New_Deaths == max(Total_New_Deaths, na.rm = TRUE))

#Which county gives minimum New Deaths:
Minimum_New_deaths = covid %>% select(Country, New_deaths) %>% group_by(Country)  %>%
  summarise(Total_New_Deaths = sum(New_deaths, na.rm = TRUE)) %>% filter(Total_New_Deaths > 0) %>% filter(Total_New_Deaths == min(Total_New_Deaths, na.rm = TRUE))


Countries_with_MaxMin_Deaths_Occured = rbind(Maximum_New_deaths,Minimum_New_deaths)

bar_heights10 = barplot(Countries_with_MaxMin_Deaths_Occured$Total_New_Deaths, 
                        names.arg = Countries_with_MaxMin_Deaths_Occured$Country, 
                        main = "Max/Min Deaths Occurred by Country", 
                        xlab = "Country", 
                        ylab = "Total New Deaths", 
                        col = terrain.colors(length(Country)), 
                        las = 1/2)
text(x = bar_heights10, y = Countries_with_MaxMin_Deaths_Occured$Total_New_Deaths/2, 
     labels = Countries_with_MaxMin_Deaths_Occured$Total_New_Deaths, 
     pos = 2, cex = 0.7, col = "black")

```


### Top 10 Countries gives maximum New Deaths:
```{r}
#Top 10 Countries gives maximum New Deaths:
Top10_Countries_New_Deaths = covid %>% select(Country, New_deaths) %>% group_by(Country)  %>% summarise(Total_New_Deaths = sum(New_deaths, na.rm = TRUE)) %>% arrange(desc(Total_New_Deaths)) %>% slice(1:10)

countries2 <- Top10_Countries_New_Deaths$Country
new_cases2 <- Top10_Countries_New_Deaths$Total_New_Deaths
bar_heights2 <- barplot(new_cases2, names.arg = countries2, col = terrain.colors(length(new_cases2)), 
                        las = 3, cex.names = 0.8, main = "Top 10 Countries by New COVID-19 Death Cases", 
                        xlab = "Countries", ylab = "Total New Deaths")
text(x = bar_heights2, y = new_cases2/2, labels = new_cases2, pos = 3, cex = 0.5, col = "black")

```


### Top 10 Countries gives minimum New Deaths - Excluding 0:
```{r}
#Bottom 10 Countries gives minimum New Deaths - Excluding 0:
Bottom10_Countries_New_Deaths = covid %>% select(Country, New_deaths) %>% group_by(Country)  %>% 
  summarise(Total_New_Deaths = sum(New_deaths, na.rm = TRUE))%>% filter(Total_New_Deaths >= 1) %>% arrange((Total_New_Deaths)) %>% slice(1:10)


countries3 <- Bottom10_Countries_New_Deaths$Country
new_cases3 <- Bottom10_Countries_New_Deaths$Total_New_Deaths
bar_heights3 <- barplot(new_cases3, names.arg = countries3, col = terrain.colors(length(new_cases3)), 
                        las = 3, cex.names = 0.8, main = "Bottom 10 Countries by New COVID-19 Death Cases", 
                        xlab = "Countries", ylab = "Total New Deaths")
text(x = bar_heights3, y = new_cases3/2, labels = new_cases3, pos = 3, cex = 0.5, col = "black")

```


COVID-19 Cases ~ By Years
=======================================================================
Row
-----------------------------------------------------------------------
### Total Deaths Over the Years
```{r}
#Which Year has maximum, minimum new Deaths occurred:
Date_Formatt = as.Date(covid$Date_reported, format = "%d-%m-%Y")
Fetching_Only_Year = format(Date_Formatt, "%Y") 

covid$Year <- Fetching_Only_Year

Total_NewDeath_By_Years = summarise(group_by(covid, Year), Total_New_Deaths = sum(New_deaths, na.rm = TRUE))

plot(Total_NewDeath_By_Years$Year, Total_NewDeath_By_Years$Total_New_Deaths,
     col = c("red","blue","green","aquamarine2","gold2"),
     pch = 18,
     cex = 0.9,
     xlab = "Year",
     ylab = "Maximum Deaths",
     main = "Total Deaths Over the Years",
     col.lab = "navyblue", col.main = "springgreen4")

legend(x = "topright", legend = c(Total_NewDeath_By_Years$Total_New_Deaths) ,
       col = c("red","blue","green","aquamarine2","gold2"), pch = 16, bty = "o", title = "Total New Deaths")
```

### Total New Cases Over the Years
```{r}
#Which Year has maximum, minimum new Cases:
Total_NewCases_By_Years = summarise(group_by(covid, Year), Total_New_Cases = sum(New_cases, na.rm = TRUE))

plot(Total_NewCases_By_Years$Year, Total_NewCases_By_Years$Total_New_Cases,
     col = c("red","blue","green","aquamarine2","gold2"),
     pch = 18,
     cex = 0.9,
     ylab = "Year",
     xlab = "Maximum Cases",
     main = "New Cases Over the Years",
     col.lab = "navyblue", col.main = "springgreen4")

legend(x = "topright", legend = c(Total_NewCases_By_Years$Total_New_Cases) ,
       col = c("red","blue","green","aquamarine2","gold2"), pch = 16, bty = "o", title = "Total New Cases")

```

### Overall Cases Over the Years
```{r}
#Total Cases Over the years:
Total_Cases_By_Years = summarise(group_by(covid, Year), Total_Cases = sum(New_cases+New_deaths, na.rm = TRUE))

plot(Total_Cases_By_Years$Year, Total_Cases_By_Years$Total_Cases,
     col = c("red","blue","green","aquamarine2","gold2"),
     pch = 18,
     cex = 0.9,
     xlab = "Year",
     ylab = "Total Cases",
     main = "Total Cases Over the Years",
     col.lab = "navyblue", col.main = "springgreen4")
legend(x = "topright", legend = c(Total_Cases_By_Years$Total_Cases) ,
       col = c("red","blue","green","aquamarine2","gold2"), pch = 16, bty = "o", title = "Total Cases")
```


COVID-19 Max/Min Cases ~ By Years
=======================================================================
Row
-----------------------------------------------------------------------

### Max/Min Deaths Occurred by Year
```{r}
#Which Year has maximum new Deaths occurred:
year_with_the_maximum_new_deaths = filter(Total_NewDeath_By_Years, Total_New_Deaths == max(Total_New_Deaths))

#Which Year has minimum new Deaths occurred:
year_with_the_minimum_new_deaths = filter(Total_NewDeath_By_Years, Total_New_Deaths == min(Total_New_Deaths))

Years_with_MaxMin_Deaths_Occured = rbind(year_with_the_maximum_new_deaths,year_with_the_minimum_new_deaths)

bar_heights10 = barplot(Years_with_MaxMin_Deaths_Occured$Total_New_Deaths, 
                        names.arg = Years_with_MaxMin_Deaths_Occured$Year, 
                        main = "COVID-19's Deadliest and Least Deadly Years", 
                        xlab = "Year", 
                        ylab = "Total New Deaths", 
                        col = terrain.colors(length(Years_with_MaxMin_Deaths_Occured$Year)), 
                        las = 1/2)
text(x = bar_heights10, y = Years_with_MaxMin_Deaths_Occured$Total_New_Deaths/2, 
     labels = Years_with_MaxMin_Deaths_Occured$Total_New_Deaths, 
     pos = 2, cex = 0.7, col = "black")

```


### Max/Min New Cases Occurred by Years
```{r}
#Which Year has maximum new Cases:
year_with_the_maximum_new_Cases = filter(Total_NewCases_By_Years, Total_New_Cases == max(Total_New_Cases))

#Which Year has minimum new Cases:
year_with_the_minimum_new_cases = filter(Total_NewCases_By_Years, Total_New_Cases == min(Total_New_Cases))

Years_with_MaxMin_Cases_Occured = rbind(year_with_the_maximum_new_Cases,year_with_the_minimum_new_cases)

bar_heights10 = barplot(Years_with_MaxMin_Cases_Occured$Total_New_Cases, 
                        names.arg = Years_with_MaxMin_Cases_Occured$Year, 
                        main = "Highest and Lowest New COVID-19 Cases by Year", 
                        xlab = "Year", 
                        ylab = "Total New Cases", 
                        col = terrain.colors(length(Years_with_MaxMin_Cases_Occured$Year)), 
                        las = 1/2)
text(x = bar_heights10, y = Years_with_MaxMin_Cases_Occured$Total_New_Cases/2, 
     labels = Years_with_MaxMin_Cases_Occured$Total_New_Cases, 
     pos = 2, cex = 0.7, col = "black")

```


### Max/Min Overall Cases Occurred by Year
```{r}
#Which Year we had a minimum covid cases:
year_with_min_TotalCases = filter(Total_Cases_By_Years, Total_Cases == min(Total_Cases))

#Which Year we had a maximum covid cases:
year_with_max_TotalCases = filter(Total_Cases_By_Years, Total_Cases == max(Total_Cases))

years_with_maxandmin_cases = rbind(year_with_min_TotalCases,year_with_max_TotalCases)

bar_heights9 = barplot(years_with_maxandmin_cases$Total_Cases, 
                       names.arg = years_with_maxandmin_cases$Year, 
                       main = "COVID-19 Cases Highest and Lowest Years", 
                       xlab = "Date Reported", 
                       ylab = "Total New Cases", 
                        col = terrain.colors(length(years_with_maxandmin_cases$Year)),
                       las = 2)
text(x = bar_heights9, y = years_with_maxandmin_cases$Total_Cases/2, 
     labels = years_with_maxandmin_cases$Total_Cases, 
     pos = 2, cex = 0.7, col = "black")
```




COVID-19 Deaths Cases ~ By Date
=======================================================================
Row
-----------------------------------------------------------------------

### Max/Min Deaths Occurred by Dates
```{r}
Total_NewDeath_ByDate = summarise(group_by(covid, Date_reported), Total_New_Deaths = sum(New_deaths, na.rm = TRUE))
# maximum new deaths occurred
Datewith_max_new_deaths <- filter(Total_NewDeath_ByDate, Total_New_Deaths == max(Total_New_Deaths, na.rm = TRUE))

# minimum new deaths occurred
Datewith_min_new_deaths <- filter(Total_NewDeath_ByDate, Total_New_Deaths == min(Total_New_Deaths, na.rm = TRUE))

# bind the two data frames
Death_Date_Occured <- rbind(Datewith_max_new_deaths, Datewith_min_new_deaths)

# create bar plot
bar_heights4 <- barplot(Death_Date_Occured$Total_New_Deaths,
                        names.arg = Death_Date_Occured$Date_reported,
                        main = "Highest and Lowest Death Toll Days",
                        xlab = "Date Reported",
                        ylab = "Total New Deaths",
                        col = terrain.colors(length(Death_Date_Occured$Date_reported)),
                        las = 2)

# add text labels
text(x = bar_heights4, y = Death_Date_Occured$Total_New_Deaths/2,
     labels = Death_Date_Occured$Total_New_Deaths,
     pos = 2, cex = 0.7, col = "black")

```



### Tracking the Peak COVID-19 Death Rates
```{r}
#Fetching the Total New Deaths by date:
Total_NewDeath_ByDate = summarise(group_by(covid, Date_reported), Total_New_Deaths = sum(New_deaths, na.rm = TRUE))

#Top 10 New Deaths occured by Date:
Top10_NewDeaths_By_Date = Total_NewDeath_ByDate %>% arrange(desc(Total_NewDeath_ByDate$Total_New_Deaths))%>% slice(1:10)

date_repoted3 = Top10_NewDeaths_By_Date$Date_reported
total_new_Deaths2 = Top10_NewDeaths_By_Date$Total_New_Deaths

bar_heights7 <- barplot(total_new_Deaths2, names.arg = date_repoted3, col = terrain.colors(length(total_new_Deaths2)), 
                        las = 3, cex.names = 0.8, main = "Dates with Highest COVID-19 Deaths", 
                        xlab = "Date Reported", ylab = "Total New Deaths")
text(x = bar_heights7, y = total_new_Deaths2/2, labels = total_new_Deaths2, pos = 3, cex = 0.5, col = "black")

```


### Tracking the Bottom COVID-19 Death Rates
```{r}
#Bottom 10 New Deaths occured by Date:
Bottom10_NewDeaths_By_Date = Total_NewDeath_ByDate %>% arrange(Total_NewDeath_ByDate$Total_New_Deaths)%>% slice(1:10)

date_repoted4 = Bottom10_NewDeaths_By_Date$Date_reported
total_new_Deaths3 = Bottom10_NewDeaths_By_Date$Total_New_Deaths

bar_heights8 <- barplot(total_new_Deaths3, names.arg = date_repoted4, col = terrain.colors(length(total_new_Deaths3)), 
                        las = 3, cex.names = 0.8, main = "Dates with Minimal COVID-19 Deaths", 
                        xlab = "Date Reported", ylab = "Total New Deaths")
text(x = bar_heights8, y = total_new_Deaths3/2, labels = total_new_Deaths3, pos = 3, cex = 0.5, col = "black")


```


COVID-19 New Cases ~ By Date
=======================================================================
Row
-----------------------------------------------------------------------

### Max/Min New Cases Occurred by Dates
```{r}
#On which date has maximum, minimum new cases occurred:
Total_NewCases_ByDate = summarise(group_by(covid, Date_reported), Total_New_Cases = sum(New_cases, na.rm = TRUE))
Total_NewCases_ByDates = arrange(Total_NewCases_ByDate,  desc(Total_New_Cases))

#maximum new cases occurred:
Datewith_max_new_cases = filter(Total_NewCases_ByDate, Total_New_Cases == max(Total_New_Cases))

#minimum new cases occurred:
Datewith_min_new_cases = filter(Total_NewCases_ByDate, Total_New_Cases == min(Total_New_Cases))

NewCases_Date_Occured = rbind(Datewith_max_new_cases,Datewith_min_new_cases)

bar_heights4 = barplot(NewCases_Date_Occured$Total_New_Cases, 
                       names.arg = NewCases_Date_Occured$Date_reported, 
                       main = "Highest and Lowest Cases Toll Days", 
                       xlab = "Date Reported", 
                       ylab = "Total New Cases", 
                       col = c("aquamarine2", "gold"), 
                       las = 2)
text(x = bar_heights4, y = NewCases_Date_Occured$Total_New_Cases/2, 
     labels = NewCases_Date_Occured$Total_New_Cases, 
     pos = 2, cex = 0.7, col = "black")

```

### Tracking the Peak COVID-19 New Cases Rates
```{r}

#Fetching the Total New Cases by date:
Total_NewCases_ByDate = summarise(group_by(covid, Date_reported), Total_New_Cases = sum(New_cases, na.rm = TRUE))
Total_NewCases_ByDates = arrange(Total_NewCases_ByDate,  desc(Total_New_Cases))


#Top 10 New cases occured by Date:
Top10_NewCases_By_Date = Total_NewCases_ByDates %>% arrange(desc(Total_NewCases_ByDates$Total_New_Cases))%>% slice(1:10)

date_repoted1 = Top10_NewCases_By_Date$Date_reported
total_new_cases1 = Top10_NewCases_By_Date$Total_New_Cases

bar_heights5 <- barplot(total_new_cases1, names.arg = date_repoted1, col = terrain.colors(length(total_new_cases1)), 
                        las = 3, cex.names = 0.8, main = "Dates with Highest COVID-19 New Cases", 
                        xlab = "Date Reported", ylab = "Total New Cases")
text(x = bar_heights5, y = total_new_cases1/2, labels = total_new_cases1, pos = 3, cex = 0.5, col = "black")

```


### Tracking the Bottom COVID-19 New Case Rates
```{r}
Total_NewCases_ByDate = summarise(group_by(covid, Date_reported), Total_New_Cases = sum(New_cases, na.rm = TRUE))
Total_NewCases_ByDates = arrange(Total_NewCases_ByDate,  desc(Total_New_Cases))


#Bottom 10 New cases occurred by Date:
Bottom10_NewCases_By_Date = Total_NewCases_ByDates %>% arrange(Total_NewCases_ByDates$Total_New_Cases)%>% slice(1:10)

date_repoted2 = Bottom10_NewCases_By_Date$Date_reported
total_new_cases2 = Bottom10_NewCases_By_Date$Total_New_Cases

bar_heights6 <- barplot(total_new_cases2, names.arg = date_repoted2, col = terrain.colors(length(total_new_cases2)), 
                        las = 3, cex.names = 0.8, main = "Dates with Minimal COVID-19 Cases", 
                        xlab = "Date Reported", ylab = "Total New Cases")
text(x = bar_heights6, y = total_new_cases2/2, labels = total_new_cases2, pos = 3, cex = 0.5, col = "black")

```


Max cumulative cases/deaths ~ By country, date-reported
=======================================================================
Row
-----------------------------------------------------------------------

### Maximum cumulative deaths by each country by date-reported
```{r}
#calculating maximum cumulative deaths by each country:
cummlative_deaths = covid %>% 
  select(Country,Date_reported, Cumulative_deaths) %>% 
  group_by(Country) %>% 
  filter(Cumulative_deaths == max(Cumulative_deaths))%>% 
  slice_max(order_by = Cumulative_deaths, n =1, with_ties = FALSE) %>%   # Ensures only the max value is taken, no ties 
  ungroup() %>% 
  arrange(desc(Cumulative_deaths))

plot_ly(data = cummlative_deaths, x = ~cummlative_deaths$Country, y = cummlative_deaths$Cumulative_deaths,color = cummlative_deaths$Cumulative_deaths, type = "bar")
```

### Maximum cumulative cases by each country by date-reported
```{r}
#calculating maximum cumulative cases by each country:
cummlative_cases = covid %>% 
  select(Country,Date_reported, Cumulative_cases) %>% 
  group_by(Country) %>% 
  filter(Cumulative_cases == max(Cumulative_cases))%>% 
  slice_max(order_by = Cumulative_cases, n =1, with_ties = FALSE) %>%   # Ensures only the max value is taken, no ties 
  ungroup() %>% 
  arrange(desc(Cumulative_cases))

plot_ly(data = cummlative_cases, x = ~cummlative_cases$Country, y = cummlative_cases$Cumulative_cases,color = cummlative_cases$Cumulative_cases, type = "bar")
```