library(readxl)
library(lubridate)
library(plyr)
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

G12<-read_excel("GOC-2012.xlsx")
G12$DATE <- as.Date(G12$DATE, format = "%Y-%m-%d") # Changing to Date format
colnames(G12)[colnames(G12)=="DATE"] <- "Date"
##11$Date <- as.Date(G12$Date, format = "%Y-%m-%d") # Changing to Date format
Dz_12Total<-G12 %>% group_by(Date) %>% summarize(Total_2012_Gen=sum(`TOTAL`),n=n())
Dz_12Goreway<-G12 %>% group_by(Date) %>% summarize(Goreway_2012_Total=sum(`SITHE GOREWAY`),n=n())

Dz_12Halton<-G12 %>% group_by(Date) %>% summarize(Halton_2012_Total=sum(HALTONHILLS),n=n())
Dz_12Portland<-G12 %>% group_by(Date) %>% summarize(Portlands_2012_Total=sum(PORTLANDS),n=n())
Dz_12Greenfeild<-G12 %>% group_by(Date) %>% summarize(GEC_2012_Total=sum(`GREENFIELD ENERGY CENTRE`),n=n())
Dz_12Brighton<-G12 %>% group_by(Date) %>% summarize(Brigton_2012_Total=sum(`BRIGHTON BEACH`),n=n())
Dz_12GB<-cbind(Dz_12Total[,-3],Dz_12Goreway[,2],Dz_12Halton[,2],Dz_12Portland[,2],Dz_12Greenfeild[,2],Dz_12Brighton[,2])
Dz_12Goreway
## # A tibble: 366 x 3
##    Date       Goreway_2012_Total     n
##    <date>                  <dbl> <int>
##  1 2012-01-01                  0    24
##  2 2012-01-02               5645    24
##  3 2012-01-03              16596    24
##  4 2012-01-04              17918    24
##  5 2012-01-05               8894    24
##  6 2012-01-06               3618    24
##  7 2012-01-07                  0    24
##  8 2012-01-08                  0    24
##  9 2012-01-09               4112    24
## 10 2012-01-10               4057    24
## # ... with 356 more rows
any(is.na(Dz_12GB))
## [1] FALSE
sum(is.na(Dz_12GB))
## [1] 0
colSums(is.na(Dz_12GB)) 
##                 Date       Total_2012_Gen   Goreway_2012_Total 
##                    0                    0                    0 
##    Halton_2012_Total Portlands_2012_Total       GEC_2012_Total 
##                    0                    0                    0 
##   Brigton_2012_Total 
##                    0
nrow(Dz_12GB)
## [1] 366
Dz_12GB<-na.omit(Dz_12GB)
any(is.na(Dz_12GB))
## [1] FALSE
nrow(Dz_12GB)
## [1] 366
head(Dz_12GB)
##         Date Total_2012_Gen Goreway_2012_Total Halton_2012_Total
## 1 2012-01-01         368186                  0                 0
## 2 2012-01-02         403791               5645              2776
## 3 2012-01-03         471208              16596             13437
## 4 2012-01-04         467064              17918                 3
## 5 2012-01-05         437383               8894                 0
## 6 2012-01-06         420185               3618                 0
##   Portlands_2012_Total GEC_2012_Total Brigton_2012_Total
## 1                    0              0                  0
## 2                 4710           8612                  0
## 3                12442          23288               3567
## 4                11872          24551               2881
## 5                 6406          16596               1721
## 6                    0           5807                  0

Goreway Power Station

any(is.na(Dz_12Goreway))
## [1] FALSE
sum(is.na(Dz_12Goreway))
## [1] 0
colSums(is.na(Dz_12Goreway)) 
##               Date Goreway_2012_Total                  n 
##                  0                  0                  0
nrow(Dz_12Goreway)
## [1] 366
Dz_12Goreway<-na.omit(Dz_12Goreway)
any(is.na(Dz_12Goreway))
## [1] FALSE
nrow(Dz_12Goreway)
## [1] 366
head(Dz_12Goreway)
## # A tibble: 6 x 3
##   Date       Goreway_2012_Total     n
##   <date>                  <dbl> <int>
## 1 2012-01-01                  0    24
## 2 2012-01-02               5645    24
## 3 2012-01-03              16596    24
## 4 2012-01-04              17918    24
## 5 2012-01-05               8894    24
## 6 2012-01-06               3618    24
Goreway_U_Status_12<-cut(Dz_12Goreway$Goreway_2012_Total,breaks = c(0,100,50000),labels = c(0,1))
Goreway_U_Status_12<-cbind(Dz_12Goreway,Goreway_U_Status_12)
#Goreway_U_Status_12
any(is.na(Goreway_U_Status_12))
## [1] TRUE
Goreway_U_Status_12[is.na(Goreway_U_Status_12)]=0
head(Goreway_U_Status_12)
##         Date Goreway_2012_Total  n Goreway_U_Status_12
## 1 2012-01-01                  0 24                   0
## 2 2012-01-02               5645 24                   1
## 3 2012-01-03              16596 24                   1
## 4 2012-01-04              17918 24                   1
## 5 2012-01-05               8894 24                   1
## 6 2012-01-06               3618 24                   1
##aa_G_12<-count(Goreway_U_Status_12,"Goreway_U_Status_12")
aa_G_12<-Goreway_U_Status_12 %>% count(Goreway_U_Status_12)
names(aa_G_12)[1]="Running_Status"
names(aa_G_12)[2]="Goreway_Run"
aa_G_12
## # A tibble: 2 x 2
##   Running_Status Goreway_Run
##   <fct>                <int>
## 1 0                       94
## 2 1                      272

Halton Hills Combined Cycle Plant

any(is.na(Dz_12Halton))
## [1] FALSE
sum(is.na(Dz_12Halton))
## [1] 0
colSums(is.na(Dz_12Halton)) 
##              Date Halton_2012_Total                 n 
##                 0                 0                 0
nrow(Dz_12Halton)
## [1] 366
Dz_12Halton<-na.omit(Dz_12Halton)
any(is.na(Dz_12Halton))
## [1] FALSE
nrow(Dz_12Halton)
## [1] 366
head(Dz_12Halton)
## # A tibble: 6 x 3
##   Date       Halton_2012_Total     n
##   <date>                 <dbl> <int>
## 1 2012-01-01                 0    24
## 2 2012-01-02              2776    24
## 3 2012-01-03             13437    24
## 4 2012-01-04                 3    24
## 5 2012-01-05                 0    24
## 6 2012-01-06                 0    24
Halton_U_Status_12<-cut(Dz_12Halton$Halton_2012_Total,breaks = c(0,100,50000),labels = c(0,1))
Halton_U_Status_12<-cbind(Dz_12Halton,Halton_U_Status_12)
Halton_U_Status_12[is.na(Halton_U_Status_12)]=0
#Halton_U_Status_12

#aa_H_10<-count(Halton_U_Status_10,"Halton_U_Status_10")
aa_H_12<-Halton_U_Status_12 %>% count(Halton_U_Status_12)
names(aa_H_12)[1]="Running_Status"
names(aa_H_12)[2]="Halton_Run"
aa_H_12
## # A tibble: 2 x 2
##   Running_Status Halton_Run
##   <fct>               <int>
## 1 0                      49
## 2 1                     317

Portlands Energy Centre

any(is.na(Dz_12Portland))
## [1] FALSE
sum(is.na(Dz_12Portland))
## [1] 0
colSums(is.na(Dz_12Portland)) 
##                 Date Portlands_2012_Total                    n 
##                    0                    0                    0
nrow(Dz_12Portland)
## [1] 366
Dz_12Portland<-na.omit(Dz_12Portland)
any(is.na(Dz_12Portland))
## [1] FALSE
nrow(Dz_12Portland)
## [1] 366
head(Dz_12Portland)
## # A tibble: 6 x 3
##   Date       Portlands_2012_Total     n
##   <date>                    <dbl> <int>
## 1 2012-01-01                    0    24
## 2 2012-01-02                 4710    24
## 3 2012-01-03                12442    24
## 4 2012-01-04                11872    24
## 5 2012-01-05                 6406    24
## 6 2012-01-06                    0    24
Portlands_U_Status_12<-cut(Dz_12Portland$Portlands_2012_Total,breaks = c(0,100,50000),labels = c(0,1))
Portlands_U_Status_12<-cbind(Dz_12Portland,Portlands_U_Status_12)
Portlands_U_Status_12[is.na(Portlands_U_Status_12)]=0
#Portlands_U_Status_12

#aa_P_10<-count(Portlands_U_Status_10,"Portlands_U_Status_10")
aa_P_12<-Portlands_U_Status_12 %>% count(Portlands_U_Status_12)
names(aa_P_12)[1]="Running_Status"
names(aa_P_12)[2]="Portland_Run"
aa_P_12
## # A tibble: 2 x 2
##   Running_Status Portland_Run
##   <fct>                 <int>
## 1 0                       135
## 2 1                       231

Greenfield Energy Centre

any(is.na(Dz_12Greenfeild))
## [1] FALSE
sum(is.na(Dz_12Greenfeild))
## [1] 0
colSums(is.na(Dz_12Greenfeild)) 
##           Date GEC_2012_Total              n 
##              0              0              0
nrow(Dz_12Greenfeild)
## [1] 366
Dz_12Greenfeild<-na.omit(Dz_12Greenfeild)
any(is.na(Dz_12Greenfeild))
## [1] FALSE
nrow(Dz_12Greenfeild)
## [1] 366
head(Dz_12Greenfeild)
## # A tibble: 6 x 3
##   Date       GEC_2012_Total     n
##   <date>              <dbl> <int>
## 1 2012-01-01              0    24
## 2 2012-01-02           8612    24
## 3 2012-01-03          23288    24
## 4 2012-01-04          24551    24
## 5 2012-01-05          16596    24
## 6 2012-01-06           5807    24
Greenfeild_U_Status_12<-cut(Dz_12Greenfeild$GEC_2012_Total,breaks = c(0,100,50000),labels = c(0,1))
Greenfeild_U_Status_12<-cbind(Dz_12Greenfeild,Greenfeild_U_Status_12)
Greenfeild_U_Status_12[is.na(Greenfeild_U_Status_12)]= 0
#Greenfeild_U_Status_12

#aa_GEC_10<-count(Greenfeild_U_Status_10,"Greenfeild_U_Status_10")
aa_GEC_12<-Greenfeild_U_Status_12 %>% count(Greenfeild_U_Status_12)
names(aa_GEC_12)[1]="Running_Status"
names(aa_GEC_12)[2]="Greenfeild_Run"
aa_GEC_12
## # A tibble: 2 x 2
##   Running_Status Greenfeild_Run
##   <fct>                   <int>
## 1 0                          78
## 2 1                         288

Brighton Beach Generating Station

any(is.na(Dz_12Brighton))
## [1] FALSE
sum(is.na(Dz_12Brighton))
## [1] 0
colSums(is.na(Dz_12Brighton)) 
##               Date Brigton_2012_Total                  n 
##                  0                  0                  0
nrow(Dz_12Brighton)
## [1] 366
Dz_12Brighton<-na.omit(Dz_12Brighton)
any(is.na(Dz_12Brighton))
## [1] FALSE
nrow(Dz_12Brighton)
## [1] 366
head(Dz_12Brighton)
## # A tibble: 6 x 3
##   Date       Brigton_2012_Total     n
##   <date>                  <dbl> <int>
## 1 2012-01-01                  0    24
## 2 2012-01-02                  0    24
## 3 2012-01-03               3567    24
## 4 2012-01-04               2881    24
## 5 2012-01-05               1721    24
## 6 2012-01-06                  0    24
Brighton_U_Status_12<-cut(Dz_12Brighton$Brigton_2012_Total,breaks = c(0,100,50000),labels = c(0,1))
Brighton_U_Status_12<-cbind(Dz_12Brighton,Brighton_U_Status_12)
Brighton_U_Status_12[is.na(Brighton_U_Status_12)]=0
#Brighton_U_Status_12

#aa_BB_10<-count(Brighton_U_Status_10,"Brighton_U_Status_10")
aa_BB_12<-Brighton_U_Status_12 %>% count(Brighton_U_Status_12)
names(aa_BB_12)[1]="Running_Status"
names(aa_BB_12)[2]="Brighton_Run"
aa_BB_12
## # A tibble: 2 x 2
##   Running_Status Brighton_Run
##   <fct>                 <int>
## 1 0                       292
## 2 1                        74
U_R_Status_12<-cbind(aa_G_12,aa_H_12[,2],aa_P_12[,2],aa_GEC_12[,2],aa_BB_12[,2])
names(U_R_Status_12)[2]="Goreway"
names(U_R_Status_12)[3]="Halton"
names(U_R_Status_12)[4]="Portlands"
names(U_R_Status_12)[5]="Greenfield"
names(U_R_Status_12)[6]="Brighton"

Barplot

count<-as.matrix(U_R_Status_12[,-1])
barplot(count)

ggplot

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

No_Run<-c(U_R_Status_12[1,2],U_R_Status_12[1,3],U_R_Status_12[1,4],U_R_Status_12[1,5],U_R_Status_12[1,6])
Run<-c(U_R_Status_12[2,2],U_R_Status_12[2,3],U_R_Status_12[2,4],U_R_Status_12[2,5],U_R_Status_12[2,6])
Days <-c(No_Run, Run)
Run_type <-c(rep("No_Run", 5), rep("Run",5))
mydata <-data.frame(Plant_Name, Days)
mydata
##    Plant_Name Days
## 1     Goreway   94
## 2      Halton   49
## 3   Portlands  135
## 4  Greenfield   78
## 5    Brighton  292
## 6     Goreway  272
## 7      Halton  317
## 8   Portlands  231
## 9  Greenfield  288
## 10   Brighton   74
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()