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

G15<-read_excel("GOC-2015.xlsx")
G15$Date <- as.Date(G15$Date, format = "%Y-%m-%d") # Changing to Date format
Dz_15Total<-G15 %>% group_by(Date) %>% summarize(Total_2015_Gen=sum(`TOTAL`),n=n())
Dz_15Goreway<-G15 %>% group_by(Date) %>% summarize(Goreway_2015_Total=sum(`SITHE GOREWAY-G11`+
                                  `SITHE GOREWAY-G12`+`SITHE GOREWAY-G13`+`SITHE GOREWAY-G15`),n=n())
Dz_15Halton<-G15 %>% group_by(Date) %>% summarize(Halton_2015_Total=sum(`HALTONHILLS-LT_G1`+`HALTONHILLS-LT_G2`+`HALTONHILLS-LT_G3`),n=n())
Dz_15Portland<-G15 %>% group_by(Date) %>% summarize(Portlands_2015_Total=sum(`PORTLANDS-G1`+`PORTLANDS-G2`+`PORTLANDS-G3`),n=n())
Dz_15Greenfeild<-G15 %>% group_by(Date) %>% summarize(GEC_2015_Total=sum(`GREENFIELD ENERGY CENTRE-G1`+
  `GREENFIELD ENERGY CENTRE-G2`+`GREENFIELD ENERGY CENTRE-G3`+`GREENFIELD ENERGY CENTRE-G4`),n=n())
Dz_15Brighton<-G15 %>% group_by(Date) %>% summarize(Brigton_2015_Total=sum(`BRIGHTON BEACH`),n=n())


head(Dz_15Total)
## # A tibble: 6 x 3
##   Date       Total_2015_Gen     n
##   <date>              <dbl> <int>
## 1 2015-01-01         448872    24
## 2 2015-01-02         451458    24
## 3 2015-01-03         451553    24
## 4 2015-01-04         445476    24
## 5 2015-01-05         488123    24
## 6 2015-01-06         506112    24
Dz_15GB<-cbind(Dz_15Total[,-3],Dz_15Goreway[,2],Dz_15Halton[,2],Dz_15Portland[,2],Dz_15Greenfeild[,2],Dz_15Brighton[,2])
head(Dz_15GB)
##         Date Total_2015_Gen Goreway_2015_Total Halton_2015_Total
## 1 2015-01-01         448872                  0                 0
## 2 2015-01-02         451458               3358                 0
## 3 2015-01-03         451553               3290              4141
## 4 2015-01-04         445476                  0              2926
## 5 2015-01-05         488123               5658              6851
## 6 2015-01-06         506112              11606              8105
##   Portlands_2015_Total GEC_2015_Total Brigton_2015_Total
## 1                 1215              0                  0
## 2                 3534           9794                  0
## 3                 3712              0                  0
## 4                    0              0                  0
## 5                 3555           7747                  0
## 6                 3188          14319               1806

Checking for missing values

any(is.na(Dz_15GB))
## [1] FALSE
sum(is.na(Dz_15GB))
## [1] 0
colSums(is.na(Dz_15GB)) 
##                 Date       Total_2015_Gen   Goreway_2015_Total 
##                    0                    0                    0 
##    Halton_2015_Total Portlands_2015_Total       GEC_2015_Total 
##                    0                    0                    0 
##   Brigton_2015_Total 
##                    0
nrow(Dz_15GB)
## [1] 365
a<-na.omit(Dz_15GB)
any(is.na(a))
## [1] FALSE

Goreway Power Station

Goreway_U_Status_15<-cut(Dz_15Goreway$Goreway_2015_Total,breaks = c(0,100,10000),labels = c(0,1))
Goreway_U_Status_15<-cbind(Dz_15Goreway,Goreway_U_Status_15)
any(is.na(Goreway_U_Status_15))
## [1] TRUE
Goreway_U_Status_15[is.na(Goreway_U_Status_15)]=0
head(Goreway_U_Status_15)
##         Date Goreway_2015_Total  n Goreway_U_Status_15
## 1 2015-01-01                  0 24                   0
## 2 2015-01-02               3358 24                   1
## 3 2015-01-03               3290 24                   1
## 4 2015-01-04                  0 24                   0
## 5 2015-01-05               5658 24                   1
## 6 2015-01-06              11606 24                   0

Counting of Running/Notrunning

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

Halton Hills Combined Cycle Plant

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

Portlands Energy Centre

Portland_U_Status_15<-cut(Dz_15GB$Portlands_2015_Total,breaks = c(0,100,10000),labels = c(0,1))
Portland_U_Status_15<-cbind(Dz_15Portland,Portland_U_Status_15)
any(is.na(Portland_U_Status_15))
## [1] TRUE
Portland_U_Status_15[is.na(Portland_U_Status_15)]=0
##head(Portland_U_Status_15)
aa_P_15<-count(Portland_U_Status_15,"Portland_U_Status_15")
names(aa_P_15)[1]="Running_Status"
names(aa_P_15)[2]="Portland_U_Status_15"
aa_P_15
## # A tibble: 1 x 2
##   Running_Status       Portland_U_Status_15
##   <chr>                               <int>
## 1 Portland_U_Status_15                  365

Greenfield Energy Centre

Greenfield_U_Status_15<-cut(Dz_15GB$GEC_2015_Total,breaks = c(0,100,10000),labels = c(0,1))
Greenfield_U_Status_15<-cbind(Dz_15Greenfeild,Greenfield_U_Status_15)
any(is.na(Greenfield_U_Status_15))
## [1] TRUE
Greenfield_U_Status_15[is.na(Greenfield_U_Status_15)]=0
##head(Greenfield_U_Status_15)
aa_GEC_15<-count(Greenfield_U_Status_15,"Greenfield_U_Status_15")
names(aa_GEC_15)[1]="Running_Status"
names(aa_GEC_15)[2]="Greenfield_U_Status_15"
aa_GEC_15
## # A tibble: 1 x 2
##   Running_Status         Greenfield_U_Status_15
##   <chr>                                   <int>
## 1 Greenfield_U_Status_15                    365

Brighton Beach Power Station

Brigton_Beach_U_Status_15<-cut(Dz_15GB$Brigton_2015_Total,breaks = c(0,100,10000),labels = c(0,1))
Brigton_Beach_U_Status_15<-cbind(Dz_15Brighton,Brigton_Beach_U_Status_15)
any(is.na(Brigton_Beach_U_Status_15))
## [1] TRUE
Brigton_Beach_U_Status_15[is.na(Brigton_Beach_U_Status_15)]=0
aa_BB_15<-count(Brigton_Beach_U_Status_15,"Brigton_Beach_U_Status_15")
names(aa_BB_15)[1]="Running_Status"
names(aa_BB_15)[2]="Brigton_Beach_U_Status_15"
aa_BB_15
## # A tibble: 1 x 2
##   Running_Status            Brigton_Beach_U_Status_15
##   <chr>                                         <int>
## 1 Brigton_Beach_U_Status_15                       365
U_R_Status_15<-cbind(aa_G_15,aa_H_15[,2],aa_P_15[,2],aa_GEC_15[,2],aa_BB_15[,2])
names(U_R_Status_15)[2]="Goreway"
names(U_R_Status_15)[3]="Halton"
names(U_R_Status_15)[4]="Portlands"
names(U_R_Status_15)[5]="Greenfield"
names(U_R_Status_15)[6]="Brigton"

Barplot

head(U_R_Status_15)
##        Running_Status Goreway Halton Portlands Greenfield Brigton
## 1 Goreway_U_Status_15     365    365       365        365     365
count<-as.matrix(U_R_Status_15[,-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_15[1,2],U_R_Status_15[1,3],U_R_Status_15[1,4],U_R_Status_15[1,5],U_R_Status_15[1,6])
yes<-c(U_R_Status_15[2,2],U_R_Status_15[2,3],U_R_Status_15[2,4],U_R_Status_15[2,5],U_R_Status_15[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).