|
| 1 | +--- |
| 2 | +title: "Comparing new_deaths in USA & UK" |
| 3 | +author: "Md Easin Hasan" |
| 4 | +date: "4/17/2021" |
| 5 | +output: word_document |
| 6 | +--- |
| 7 | +```{r} |
| 8 | +data<-read.csv(file="owid-covid-data417.csv",header=TRUE) |
| 9 | +dim(data) |
| 10 | +data1 <- data[data$iso_code == "USA", ] |
| 11 | +data2 <- data[data$iso_code == "GBR", ] |
| 12 | +data3<-rbind(data1,data2) |
| 13 | +country <- ifelse(data3$iso_code == "USA",0,1) |
| 14 | +data4 <- cbind(country,data3) |
| 15 | +data4$country<-as.factor(data4$country) |
| 16 | +data4$country<-factor(data4$country,levels=c(0,1),labels=c("USA", "UK")) |
| 17 | +data5 <- data4[,-c(2)] |
| 18 | +dat2 <-data5[,c(1,4,9)] |
| 19 | +colnames(dat2) |
| 20 | +
|
| 21 | +``` |
| 22 | +We have obtained the data-set on COVID-19 (coronavirus) by Our World in Data. They have up-to-date data on confirmed cases, deaths, hospitalizations, testing, and vaccinations, throughout the duration of the COVID-19 pandemic. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +```{r, warning=FALSE} |
| 27 | +library(ggplot2) |
| 28 | +library(gganimate) |
| 29 | +library(viridis) |
| 30 | +library(scales) |
| 31 | +theme_set(theme_bw()) |
| 32 | +plot <- ggplot(dat2, aes(x = as.Date(date), y = new_deaths, color = country)) + |
| 33 | + geom_line()+ |
| 34 | + geom_point(alpha = 0.3)+ |
| 35 | + scale_x_date(labels = date_format("%m-%d-%Y"))+ |
| 36 | + labs(x = "date")+ |
| 37 | + labs(y = "Number of new_deaths")+ |
| 38 | + ggtitle("Plot of new deaths in USA & UK \n due to COVID-19") |
| 39 | +plot |
| 40 | +
|
| 41 | +
|
| 42 | +
|
| 43 | +
|
| 44 | +``` |
| 45 | + |
| 46 | +From this visualization, we can compare the new_deaths in USA & UK due to COVID-19. In addition, we can figure out the number of new_deaths. |
| 47 | + |
| 48 | + |
| 49 | +# Data Visualization improvement: |
| 50 | + |
| 51 | +```{r, warning=FALSE} |
| 52 | +library(magick) |
| 53 | +plot <- ggplot(dat2, aes(x = as.Date(date), y = new_deaths, color = country)) + |
| 54 | + geom_line()+ |
| 55 | + geom_point(alpha = 0.7)+ |
| 56 | + transition_reveal(as.Date(date))+ |
| 57 | + scale_x_date(labels = date_format("%m-%d-%Y"))+ |
| 58 | + labs(x = "date")+ |
| 59 | + labs(y = "Number of new_deaths")+ |
| 60 | + ggtitle("Plot of new deaths in USA & UK \n due to COVID-19") |
| 61 | +animation <- animate(plot, nframes=100, renderer=magick_renderer()) |
| 62 | +animation |
| 63 | +image_write_gif(animation, 'animation.gif') |
| 64 | +
|
| 65 | +``` |
0 commit comments