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")
library("RPostgreSQL")
library("devtools")
library("remotes")
library("DBI") library("forecast")
#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')
#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')
ggplot(data=b7A1,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A1 health board")

#Data and plot for 7A2board b7A2<-hospitalindividual('7A2')
ggplot(data=b7A2,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A2 health board")

#Data and plot for 7A3board b7A3<-hospitalindividual('7A3')
ggplot(data=b7A3,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A3 health board")

#Data and plot for 7A4board b7A4<-hospitalindividual('7A4')
ggplot(data=b7A4,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A4 health board")

#Data and plot for 7A5board b7A5<-hospitalindividual('7A5')
ggplot(data=b7A5,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A5 health board")

#Data and plot for 7A6board b7A6<-hospitalindividual('7A6')
ggplot(data=b7A6,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for 7A6 health board")

#Data and plot for RQFboard bRQF<-hospitalindividual('RQF')
ggplot(data=bRQF,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for RQF health board")

#Data and plot for wales wales<-hospitalindividual('W92000004')
ggplot(data=wales,aes(x=Date_Code,y=numofpatients,group=1))+geom_point()+geom_line()+ggtitle("number of covid patients for wales health board")
