This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# code written by Shashidhar Ameenpur in R studio
# written on 31-10-2021 and code below is for data  analysis of covid data from wales

#importing all the packages required for data processiong 
library("jsonlite")
library("tidyverse")
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.3     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter()  masks stats::filter()
## x purrr::flatten() masks jsonlite::flatten()
## x dplyr::lag()     masks stats::lag()
library("RPostgreSQL")
## Loading required package: DBI
library("devtools")
## Loading required package: usethis
library("remotes")
## 
## Attaching package: 'remotes'
## The following objects are masked from 'package:devtools':
## 
##     dev_package_deps, install_bioc, install_bitbucket, install_cran,
##     install_deps, install_dev, install_git, install_github,
##     install_gitlab, install_local, install_svn, install_url,
##     install_version, update_packages
## The following object is masked from 'package:usethis':
## 
##     git_credentials
library("DBI")
library("forecast")
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
#importing data from api link in to R studio 
json_file <- "http://open.statswales.gov.wales/en-gb/dataset/hlth0091"
json_data <- jsonlite::fromJSON(json_file)
#converting list data into table form for further processing
df<-json_data[2]
statewales<-df[[1]]
# created database named covidwales in postgressql database
#code for connecting R studio with postgresql database
con <- dbConnect(RPostgres::Postgres(), host = "localhost", port = "5433",dbname="covidwales",
        user = "postgres", password = .rs.askForPassword(prompt = "please provide passowrd for postgresql"))
## Error in .rs.askForPassword(prompt = "please provide passowrd for postgresql"): could not find function ".rs.askForPassword"
#importing data from R studio into postgresql
dbWriteTable(con, "statewales",statewales,overwrite = T )
## Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbWriteTable': object 'con' not found
#reorgnising data so that meaningfull analysis can be done, filtering with indicator co_hosps_c19 as it
#contains total number of covid patients which includes both suspect and confirmed
coviddata<-statewales%>%group_by(LocalHealthBoard_Code,Date_Code,Indicator_Code)%>%
  summarise(numofpatients=sum(as.numeric(Data)),LocalHealthBoard_Code,Indicator_Code,Date_ItemName_ENG)%>%
  filter(row_number()==1&Indicator_Code=='CO_Hosps_C19')
## `summarise()` has grouped output by 'LocalHealthBoard_Code', 'Date_Code', 'Indicator_Code'. You can override using the `.groups` argument.
#function for extracting data for each health board
hospitalindividual<-function(x){
  y<-coviddata%>%filter(LocalHealthBoard_Code==x)%>%select(Date_Code,numofpatients)
  return(y)

}
#Data and plot for 7A1board
b7A1<-hospitalindividual('7A1')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A1,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A1 health board")
plot of chunk unnamed-chunk-1
#Data and plot for 7A2board
b7A2<-hospitalindividual('7A2')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A2,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A2 health board")
plot of chunk unnamed-chunk-1
#Data and plot for 7A3board
b7A3<-hospitalindividual('7A3')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A3,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A3 health board")
plot of chunk unnamed-chunk-1
#Data and plot for 7A4board
b7A4<-hospitalindividual('7A4')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A4,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A4 health board")
plot of chunk unnamed-chunk-1
#Data and plot for 7A5board
b7A5<-hospitalindividual('7A5')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A5,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A5 health board")
plot of chunk unnamed-chunk-1
#Data and plot for 7A6board
b7A6<-hospitalindividual('7A6')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=b7A6,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A6 health board")
plot of chunk unnamed-chunk-1
#Data and plot for RQFboard
bRQF<-hospitalindividual('RQF')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=bRQF,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for RQF health board")
plot of chunk unnamed-chunk-1
#Data and plot for wales
wales<-hospitalindividual('W92000004')
## Adding missing grouping variables: `LocalHealthBoard_Code`, `Indicator_Code`
ggplot(data=wales,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for wales health board")
plot of chunk unnamed-chunk-1