├── vignettes ├── .gitignore └── IranCovid.Rmd ├── NAMESPACE ├── .Rbuildignore ├── logo.png ├── coronaa.png ├── .gitignore ├── confirmed.png ├── man └── figures │ └── logo.png ├── tests └── testthat.R ├── IranCovid.Rproj ├── logomaker.R ├── DESCRIPTION ├── R ├── CountryTimeSeries.R ├── CovidWorldMap.R └── UpdateCovid.R ├── LICENSE.md └── README.md /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | exportPattern("^[[:alpha:]]+") 2 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pariyamd/IranCovid/HEAD/logo.png -------------------------------------------------------------------------------- /coronaa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pariyamd/IranCovid/HEAD/coronaa.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | -------------------------------------------------------------------------------- /confirmed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pariyamd/IranCovid/HEAD/confirmed.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pariyamd/IranCovid/HEAD/man/figures/logo.png -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(IranCovid) 3 | 4 | # test_check("IranCovid") 5 | 6 | # CovidWorldMap(20,10,2020,"Confirmed Cases") 7 | -------------------------------------------------------------------------------- /IranCovid.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /vignettes/IranCovid.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Covid-19 Cases Clean Data and Figures" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Covid-19 Cases Clean Data and Figures} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library(IranCovid) 19 | ``` 20 | -------------------------------------------------------------------------------- /logomaker.R: -------------------------------------------------------------------------------- 1 | library(hexSticker) 2 | library(showtext) 3 | 4 | 5 | borders("Iran") 6 | ggplot() + geom_polygon(data = usa, aes(x=long, y = lat, group = group)) + 7 | coord_fixed(1.3) 8 | 9 | font_add_google("Inconsolata") 10 | imgurl <- system.file("~/Documents/hesaba/HW7/IranCovid/corona.png", package="IranCovid") 11 | 12 | sticker("coronaa.png",package="IranCovid",p_color = "#f39c12", 13 | p_size=20, s_x=1, s_y=.8, s_width=0.5, s_height=0.3, 14 | h_fill="#ffffff", 15 | h_color="#f39c12", 16 | p_family = "Inconsolata", 17 | filename="logo.png") 18 | 19 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: IranCovid 2 | Type: Package 3 | Title: What the Package Does (Title Case) 4 | Version: 0.1.0 5 | Author: Who wrote it 6 | Maintainer: The package maintainer 7 | Description: More about what it does (maybe more than one line) 8 | Use four spaces when indenting paragraphs within the Description. 9 | License: What license is it under? 10 | Encoding: UTF-8 11 | LazyData: true 12 | Suggests: 13 | testthat, 14 | knitr, 15 | rmarkdown 16 | Roxygen: list(markdown = TRUE) 17 | RoxygenNote: 7.1.1 18 | URL: https://github.com/pariyamd/IranCovid 19 | BugReports: https://github.com/pariyamd/IranCovid/issues 20 | Imports: 21 | lubridate, 22 | dplyr, 23 | maptools, 24 | stringr, 25 | tidyr, 26 | maps, 27 | ggmap 28 | VignetteBuilder: knitr 29 | -------------------------------------------------------------------------------- /R/CountryTimeSeries.R: -------------------------------------------------------------------------------- 1 | #' @title CountryTimeSeries 2 | #' @description shows a figure of covid cases in a period of time for a specific country 3 | #' @param from start of the period with the format of "%m-%d-%Y" 4 | #' @param end end of the period with the format of "%m-%d-%Y" 5 | #' @param country 6 | #' @return plots a figure of covid cases in a period of time in the determied country 7 | library(lubridate) 8 | library(dplyr) 9 | CountryTimeSeries<-function(from="04-20-2020",to="10-28-2020",country="Iran"){ 10 | 11 | jh_data<-IranCovid::UpdateCovid() 12 | period<-jh_data%>% 13 | filter(as.Date(from,"%m-%d-%Y")<=as.Date(Date,"%m-%d-%Y") & as.Date(Date,"%m-%d-%Y")<=as.Date(to,"%m-%d-%Y"))%>% 14 | filter(Country.Region==country)%>% 15 | arrange(Date) 16 | 17 | ggplot(period,aes(x = as.Date(Date,"%m-%d-%Y"), y = Num,color=Type)) + 18 | geom_line() 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Pariya Mehrbod 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/CovidWorldMap.R: -------------------------------------------------------------------------------- 1 | #' @title CovidWorldMap 2 | #' @description This function shows visual distribution of death/recovered/confirmed cases over a world map in a spesific date 3 | #' @param day the day of wanted date 4 | #' @param month the month of wanted date 5 | #' @param year the year of wanted date 6 | #' @param type type of data which can be of :"Recovered Cases","Confirmed Cases" and "Death Cases" 7 | #' @return A world map figure which every country is shown by a colored point and the number of cases determines the size of each point 8 | #' @examples IranCovid::CovidWorldMap(2,4,2020,"Death Cases") 9 | 10 | library(maptools) 11 | library(maps) 12 | library(stringr) 13 | library(ggmap) 14 | CovidWorldMap<-function(day=1,month=10,year=2020,type="Confirmed Cases"){ 15 | 16 | jh_data<-IranCovid::UpdateCovid() 17 | 18 | if (str_length(day)<2){ 19 | day=str_c("0",day) 20 | } 21 | if (str_length(month)<2){ 22 | month=str_c("0",month) 23 | } 24 | 25 | world_date<-jh_data%>%filter(Date==paste(month,day,year,sep='-'))%>% 26 | filter(Type==type) 27 | mapWorld <- borders("world", fill="white") 28 | ggplot() + 29 | mapWorld+ 30 | geom_point(data=world_date, aes(x=Long, y=Lat,color=Country.Region,size=Num) )+ 31 | theme(legend.position = "none")+ 32 | labs(title = type) 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # IranCovid 3 | 4 | [![CRAN status](https://www.r-pkg.org/badges/version/IranCovid)](https://CRAN.R-project.org/package=IranCovid) 5 | [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) 6 | 7 | 8 | The goal of IranCovid is to fetch Covid-19 data from [Johns Hopkins University](https://github.com/CSSEGISandData/COVID-19) Covid-19 Data repository and cleans the data. 9 | you can also plot pretty figures with IranCovid, like plotting a colorful world map of covid-19 cases or plotting number of cases time series during a period of time for an arbitrary country 10 | 11 | ## Installation 12 | 13 | You can install the released version of IranCovid from [CRAN](https://CRAN.R-project.org) with: 14 | 15 | ``` r 16 | install.packages("IranCovid") 17 | ``` 18 | 19 | ## Example 20 | 21 | This is a basic example which shows you how to plot a world map on 10-20-2020 for covid-19 Confirmed Cases: 22 | 23 | ``` r 24 | library(IranCovid) 25 | ## basic example code 26 | IranCovid::CovidWorldMap(10,20,2020,"Confirmed Cases") 27 | ``` 28 | and here is your world map figure: 29 | 30 | ![confirmed cases world map](https://github.com/pariyamd/IranCovid/blob/master/confirmed.png) 31 | 32 | -------------------------------------------------------------------------------- /R/UpdateCovid.R: -------------------------------------------------------------------------------- 1 | #' @title UpdateCovid 2 | #' @description this function fetches data from John Hopkins dataset 3 | #' and reformats column names in a way that each row represents 4 | #' number of cases in a specific country for a specific date 5 | #' @return a clean dataframe computed from John Hopkins dataset 6 | 7 | library(dplyr) 8 | library(tidyr) 9 | library(stringr) 10 | library(lubridate) 11 | 12 | UpdateCovid<-function(){ 13 | 14 | confirmed_global_raw=read.csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")) 15 | recovered_global_raw=read.csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")) 16 | death_global_raw=read.csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")) 17 | 18 | # reformat column Date names for confirmed cases 19 | columns=colnames(confirmed_global_raw) 20 | columns[str_detect(columns,"^X")]=format(strptime(as.character(columns[str_detect(columns,"^X")]), "X%m.%d.%y"),"%m-%d-%Y") 21 | colnames(confirmed_global_raw)=columns 22 | confirmed_global<- 23 | confirmed_global_raw%>% 24 | mutate(Type="Confirmed Cases") 25 | 26 | # reformat column Date names for recovered cases 27 | columns=colnames(recovered_global_raw) 28 | columns[str_detect(columns,"^X")]=format(strptime(as.character(columns[str_detect(columns,"^X")]), "X%m.%d.%y"),"%m-%d-%Y") 29 | colnames(recovered_global_raw)=columns 30 | recovered_global<- 31 | recovered_global_raw%>% 32 | mutate(Type="Recovered Cases") 33 | 34 | # reformat column Date names for Death cases 35 | columns=colnames(death_global_raw) 36 | columns[str_detect(columns,"^X")]=format(strptime(as.character(columns[str_detect(columns,"^X")]), "X%m.%d.%y"),"%m-%d-%Y") 37 | colnames(death_global_raw)=columns 38 | death_global<- 39 | death_global_raw%>% 40 | mutate(Type="Death Cases") 41 | 42 | output<-rbind(recovered_global,confirmed_global,death_global) 43 | date_columns=c(setdiff(colnames(output),c("Province.State","Country.Region","Lat","Long","Type"))) 44 | 45 | output<-output%>%gather(Date,Num,date_columns)%>% 46 | arrange(Country.Region,Date,Type,Num) 47 | return(output) 48 | } 49 | --------------------------------------------------------------------------------