library(readxl)
library(lubridate)
library(dplyr)
library(tidyr)

Natural gas combine cycle plant generation depends upon market demand . Attemp has been made to calculate the number of days plant was supplying power to grid.It is a first attempt for a comparitive study with counting wind generating days

G17<-read_excel("GOC-2017.xlsx")
G17$Date <- as.Date(G17$Date, format = "%Y-%m-%d") # Changing to Date format
Dz_17Total<-G17 %>% group_by(Date) %>% summarize(Total_2017_Gen=sum(`TOTAL`),n=n())
Dz_17Goreway<-G17 %>% group_by(Date) %>% summarize(Goreway_2017_Total=sum(`SITHE GOREWAY-G11`+
                                  `SITHE GOREWAY-G12`+`SITHE GOREWAY-G13`+`SITHE GOREWAY-G15`),n=n())
Dz_17Halton<-G17 %>% group_by(Date) %>% summarize(Halton_2017_Total=sum(`HALTONHILLS-LT_G1`+`HALTONHILLS-LT_G2`+`HALTONHILLS-LT_G3`),n=n())
Dz_17Portland<-G17 %>% group_by(Date) %>% summarize(Portlands_2017_Total=sum(`PORTLANDS-G1`+`PORTLANDS-G2`+`PORTLANDS-G3`),n=n())
Dz_17Greenfeild<-G17 %>% group_by(Date) %>% summarize(GEC_2017_Total=sum(`GREENFIELD ENERGY CENTRE-G1`+
  `GREENFIELD ENERGY CENTRE-G2`+`GREENFIELD ENERGY CENTRE-G3`+`GREENFIELD ENERGY CENTRE-G4`),n=n())
Dz_17Brighton<-G17 %>% group_by(Date) %>% summarize(Brigton_2017_Total=sum(`BRIGHTON BEACH`),n=n())


head(Dz_17Total)
## # A tibble: 6 x 3
##   Date       Total_2017_Gen     n
##   <date>              <dbl> <int>
## 1 2017-01-01         395129    24
## 2 2017-01-02         400509    24
## 3 2017-01-03         410456    24
## 4 2017-01-04         444225    24
## 5 2017-01-05         450843    24
## 6 2017-01-06         447011    24
Dz_17GB<-cbind(Dz_17Total[,-3],Dz_17Goreway[,2],Dz_17Halton[,2],Dz_17Portland[,2],Dz_17Greenfeild[,2],Dz_17Brighton[,2])
head(Dz_17GB)
##         Date Total_2017_Gen Goreway_2017_Total Halton_2017_Total
## 1 2017-01-01         395129                  0                 0
## 2 2017-01-02         400509                  0                 0
## 3 2017-01-03         410456                  0                 0
## 4 2017-01-04         444225                  0                 0
## 5 2017-01-05         450843                  0              6762
## 6 2017-01-06         447011                  0              7965
##   Portlands_2017_Total GEC_2017_Total Brigton_2017_Total
## 1                    0              0                  0
## 2                    0              0                  0
## 3                 1435              0                  0
## 4                    0             85                  0
## 5                 1358            155                  0
## 6                 2494           8816               6361

Checking for missing values

any(is.na(Dz_17GB))
## [1] FALSE
sum(is.na(Dz_17GB))
## [1] 0
colSums(is.na(Dz_17GB)) 
##                 Date       Total_2017_Gen   Goreway_2017_Total 
##                    0                    0                    0 
##    Halton_2017_Total Portlands_2017_Total       GEC_2017_Total 
##                    0                    0                    0 
##   Brigton_2017_Total 
##                    0
nrow(Dz_17GB)
## [1] 365
a<-na.omit(Dz_17GB)
any(is.na(a))
## [1] FALSE

Goreway Power Station

Goreway_U_Status_17<-cut(Dz_17Goreway$Goreway_2017_Total,breaks = c(0,100,10000),labels = c(0,1))
Goreway_U_Status_17<-cbind(Dz_17Goreway,Goreway_U_Status_17)
any(is.na(Goreway_U_Status_17))
## [1] TRUE
Goreway_U_Status_17[is.na(Goreway_U_Status_17)]=0
head(Goreway_U_Status_17)
##         Date Goreway_2017_Total  n Goreway_U_Status_17
## 1 2017-01-01                  0 24                   0
## 2 2017-01-02                  0 24                   0
## 3 2017-01-03                  0 24                   0
## 4 2017-01-04                  0 24                   0
## 5 2017-01-05                  0 24                   0
## 6 2017-01-06                  0 24                   0

Counting of Running/Notrunning

library(plyr)
aa_G_17<-count(Goreway_U_Status_17,"Goreway_U_Status_17")
names(aa_G_17)[1]="Running_Status"
names(aa_G_17)[2]="Goreway_Running_Frequency"
aa_G_17
## # A tibble: 1 x 2
##   Running_Status      Goreway_Running_Frequency
##   <chr>                                   <int>
## 1 Goreway_U_Status_17                       365

Halton Hills Generating Station

Halton_U_Status_17<-cut(Dz_17Halton$Halton_2017_Total,breaks = c(0,100,10000),labels = c(0,1))
Halton_U_Status_17<-cbind(Dz_17Halton,Halton_U_Status_17)
any(is.na(Halton_U_Status_17))
## [1] TRUE
Halton_U_Status_17[is.na(Halton_U_Status_17)]=0
##head(Halton_U_Status_18)
aa_H_17<-count(Halton_U_Status_17,"Halton_U_Status_17")
names(aa_H_17)[1]="Running_Status"
names(aa_H_17)[2]="Halton_Running_Frequency"
aa_H_17
## # A tibble: 1 x 2
##   Running_Status     Halton_Running_Frequency
##   <chr>                                 <int>
## 1 Halton_U_Status_17                      365

Portlands Energy Centre

Portland_U_Status_17<-cut(Dz_17GB$Portlands_2017_Total,breaks = c(0,100,10000),labels = c(0,1))
Portland_U_Status_17<-cbind(Dz_17Portland,Portland_U_Status_17)
any(is.na(Portland_U_Status_17))
## [1] TRUE
Portland_U_Status_17[is.na(Portland_U_Status_17)]=0
##head(Portland_U_Status_17)
aa_P_17<-count(Portland_U_Status_17,"Portland_U_Status_17")
names(aa_P_17)[1]="Running_Status"
names(aa_P_17)[2]="Portland_U_Status_17"
aa_P_17
## # A tibble: 1 x 2
##   Running_Status       Portland_U_Status_17
##   <chr>                               <int>
## 1 Portland_U_Status_17                  365

Greenfield Energy Centre

Greenfield_U_Status_17<-cut(Dz_17GB$GEC_2017_Total,breaks = c(0,100,10000),labels = c(0,1))
Greenfield_U_Status_17<-cbind(Dz_17Greenfeild,Greenfield_U_Status_17)
any(is.na(Greenfield_U_Status_17))
## [1] TRUE
Greenfield_U_Status_17[is.na(Greenfield_U_Status_17)]=0
##head(Greenfield_U_Status_17)
aa_GEC_17<-count(Greenfield_U_Status_17,"Greenfield_U_Status_17")
names(aa_GEC_17)[1]="Running_Status"
names(aa_GEC_17)[2]="Greenfield_U_Status_17"
aa_GEC_17
## # A tibble: 1 x 2
##   Running_Status         Greenfield_U_Status_17
##   <chr>                                   <int>
## 1 Greenfield_U_Status_17                    365

Brighton Beach Power Station

Brigton_Beach_U_Status_17<-cut(Dz_17GB$Brigton_2017_Total,breaks = c(0,100,10000),labels = c(0,1))
Brigton_Beach_U_Status_17<-cbind(Dz_17Brighton,Brigton_Beach_U_Status_17)
any(is.na(Brigton_Beach_U_Status_17))
## [1] TRUE
Brigton_Beach_U_Status_17[is.na(Brigton_Beach_U_Status_17)]=0
aa_BB_17<-count(Brigton_Beach_U_Status_17,"Brigton_Beach_U_Status_17")
names(aa_BB_17)[1]="Running_Status"
names(aa_BB_17)[2]="Brigton_Beach_U_Status_17"
aa_BB_17
## # A tibble: 1 x 2
##   Running_Status            Brigton_Beach_U_Status_17
##   <chr>                                         <int>
## 1 Brigton_Beach_U_Status_17                       365
U_R_Status_17<-cbind(aa_G_17,aa_H_17[,2],aa_P_17[,2],aa_GEC_17[,2],aa_BB_17[,2])
names(U_R_Status_17)[2]="Goreway"
names(U_R_Status_17)[3]="Halton"
names(U_R_Status_17)[4]="Portlands"
names(U_R_Status_17)[5]="Greenfield"
names(U_R_Status_17)[6]="Brigton"

Barplot

head(U_R_Status_17)
##        Running_Status Goreway Halton Portlands Greenfield Brigton
## 1 Goreway_U_Status_17     365    365       365        365     365
count<-as.matrix(U_R_Status_17[,-1])
uk<-c("0","1")
barplot(count)

ggplot

library(ggplot2)
Plant_Name <-rep(c("Goreway", "Halton", "Portlands", "Greenfield", "Brigton"), 2)

no<-c(U_R_Status_17[1,2],U_R_Status_17[1,3],U_R_Status_17[1,4],U_R_Status_17[1,5],U_R_Status_17[1,6])
yes<-c(U_R_Status_17[2,2],U_R_Status_17[2,3],U_R_Status_17[2,4],U_R_Status_17[2,5],U_R_Status_17[2,6])
Days <-c(no, yes)
Run_type <-c(rep("no", 5), rep("yes",5))
mydata <-data.frame(Plant_Name, Days)
mydata
##    Plant_Name Days
## 1     Goreway  365
## 2      Halton  365
## 3   Portlands  365
## 4  Greenfield  365
## 5     Brigton  365
## 6     Goreway   NA
## 7      Halton   NA
## 8   Portlands   NA
## 9  Greenfield   NA
## 10    Brigton   NA
p <-ggplot(mydata, aes(Plant_Name, Days))
p +geom_bar(stat= "identity",aes(fill=Run_type),position="dodge")+xlab("Plants Name")+ylab("Number of Days")+theme_bw()

Labels to a dodged barplot

ggplot(data=mydata, aes(x=Plant_Name, y=Days, fill=Run_type)) +
  geom_bar(stat="identity", position=position_dodge())+
  geom_text(aes(label=Days), vjust=1.6, color="white",
            position = position_dodge(0.9), size=3.5)+
  scale_fill_brewer(palette="Paired")+
  theme_minimal()
## Warning: Removed 5 rows containing missing values (geom_bar).
## Warning: Removed 5 rows containing missing values (geom_text).