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

G13<-read_excel("GOC-2013.xlsx")
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting logical in DL8767 / R8767C116: got 'pppp'
## New names:
## * `` -> ...113
## * `` -> ...114
## * `` -> ...115
## * `` -> ...116
G13$Date <- as.Date(G13$Date, format = "%Y-%m-%d") # Changing to Date format
#colnames(G13)[colnames(G13)=="DATE"] <- "Date"
##11$Date <- as.Date(G12$Date, format = "%Y-%m-%d") # Changing to Date format
Dz_13Total<-G13 %>% group_by(Date) %>% summarize(Total_2013_Gen=sum(`TOTAL`),n=n())
Dz_13Goreway<-G13 %>% group_by(Date) %>% summarize(Goreway_2013_Total=sum(`SITHE GOREWAY`),n=n())

Dz_13Halton<-G13 %>% group_by(Date) %>% summarize(Halton_2013_Total=sum(HALTONHILLS),n=n())
Dz_13Portland<-G13 %>% group_by(Date) %>% summarize(Portlands_2013_Total=sum(PORTLANDS),n=n())
Dz_13Greenfeild<-G13 %>% group_by(Date) %>% summarize(GEC_2013_Total=sum(`GREENFIELD ENERGY CENTRE`),n=n())
Dz_13Brighton<-G13 %>% group_by(Date) %>% summarize(Brigton_2013_Total=sum(`BRIGHTON BEACH`),n=n())
Dz_13GB<-cbind(Dz_13Total[,-3],Dz_13Goreway[,2],Dz_13Halton[,2],Dz_13Portland[,2],Dz_13Greenfeild[,2],Dz_13Brighton[,2])
Dz_13Goreway
## # A tibble: 366 x 3
##    Date       Goreway_2013_Total     n
##    <date>                  <dbl> <int>
##  1 2013-01-01                  0    24
##  2 2013-01-02              11716    24
##  3 2013-01-03              14626    24
##  4 2013-01-04              10032    24
##  5 2013-01-05               4083    24
##  6 2013-01-06               4760    24
##  7 2013-01-07              14990    24
##  8 2013-01-08               9167    24
##  9 2013-01-09               3136    24
## 10 2013-01-10               3933    24
## # ... with 356 more rows
any(is.na(Dz_13GB))
## [1] TRUE
sum(is.na(Dz_13GB))
## [1] 7
colSums(is.na(Dz_13GB)) 
##                 Date       Total_2013_Gen   Goreway_2013_Total 
##                    1                    1                    1 
##    Halton_2013_Total Portlands_2013_Total       GEC_2013_Total 
##                    1                    1                    1 
##   Brigton_2013_Total 
##                    1
nrow(Dz_13GB)
## [1] 366
Dz_13GB<-na.omit(Dz_13GB)
any(is.na(Dz_13GB))
## [1] FALSE
nrow(Dz_13GB)
## [1] 365
head(Dz_13GB)
##         Date Total_2013_Gen Goreway_2013_Total Halton_2013_Total
## 1 2013-01-01         413181                  0                 0
## 2 2013-01-02         473505              11716             11691
## 3 2013-01-03         489156              14626              9094
## 4 2013-01-04         465213              10032              3370
## 5 2013-01-05         420954               4083              5370
## 6 2013-01-06         419761               4760              2903
##   Portlands_2013_Total GEC_2013_Total Brigton_2013_Total
## 1                    0           4708                  0
## 2                 7542          14465                  0
## 3                 8191          13579                  0
## 4                    0           4273                  0
## 5                    0              0                  0
## 6                 4368              0                  0

Goreway Power Station

any(is.na(Dz_13Goreway))
## [1] TRUE
sum(is.na(Dz_13Goreway))
## [1] 2
colSums(is.na(Dz_13Goreway)) 
##               Date Goreway_2013_Total                  n 
##                  1                  1                  0
nrow(Dz_13Goreway)
## [1] 366
Dz_13Goreway<-na.omit(Dz_13Goreway)
any(is.na(Dz_13Goreway))
## [1] FALSE
nrow(Dz_13Goreway)
## [1] 365
head(Dz_13Goreway)
## # A tibble: 6 x 3
##   Date       Goreway_2013_Total     n
##   <date>                  <dbl> <int>
## 1 2013-01-01                  0    24
## 2 2013-01-02              11716    24
## 3 2013-01-03              14626    24
## 4 2013-01-04              10032    24
## 5 2013-01-05               4083    24
## 6 2013-01-06               4760    24
Goreway_U_Status_13<-cut(Dz_13Goreway$Goreway_2013_Total,breaks = c(0,100,50000),labels = c(0,1))
Goreway_U_Status_13<-cbind(Dz_13Goreway,Goreway_U_Status_13)
#Goreway_U_Status_13
any(is.na(Goreway_U_Status_13))
## [1] TRUE
Goreway_U_Status_13[is.na(Goreway_U_Status_13)]=0
head(Goreway_U_Status_13)
##         Date Goreway_2013_Total  n Goreway_U_Status_13
## 1 2013-01-01                  0 24                   0
## 2 2013-01-02              11716 24                   1
## 3 2013-01-03              14626 24                   1
## 4 2013-01-04              10032 24                   1
## 5 2013-01-05               4083 24                   1
## 6 2013-01-06               4760 24                   1
##aa_G_13<-count(Goreway_U_Status_13,"Goreway_U_Status_13")
aa_G_13<-Goreway_U_Status_13 %>% count(Goreway_U_Status_13)
names(aa_G_13)[1]="Running_Status"
names(aa_G_13)[2]="Goreway_Run"
aa_G_13
## # A tibble: 2 x 2
##   Running_Status Goreway_Run
##   <fct>                <int>
## 1 0                      186
## 2 1                      179

Halton Hills Combined Cycle Plant

any(is.na(Dz_13Halton))
## [1] TRUE
sum(is.na(Dz_13Halton))
## [1] 2
colSums(is.na(Dz_13Halton)) 
##              Date Halton_2013_Total                 n 
##                 1                 1                 0
nrow(Dz_13Halton)
## [1] 366
Dz_13Halton<-na.omit(Dz_13Halton)
any(is.na(Dz_13Halton))
## [1] FALSE
nrow(Dz_13Halton)
## [1] 365
head(Dz_13Halton)
## # A tibble: 6 x 3
##   Date       Halton_2013_Total     n
##   <date>                 <dbl> <int>
## 1 2013-01-01                 0    24
## 2 2013-01-02             11691    24
## 3 2013-01-03              9094    24
## 4 2013-01-04              3370    24
## 5 2013-01-05              5370    24
## 6 2013-01-06              2903    24
Halton_U_Status_13<-cut(Dz_13Halton$Halton_2013_Total,breaks = c(0,100,50000),labels = c(0,1))
Halton_U_Status_13<-cbind(Dz_13Halton,Halton_U_Status_13)
Halton_U_Status_13[is.na(Halton_U_Status_13)]=0
#Halton_U_Status_13

#aa_H_10<-count(Halton_U_Status_10,"Halton_U_Status_10")
aa_H_13<-Halton_U_Status_13 %>% count(Halton_U_Status_13)
names(aa_H_13)[1]="Running_Status"
names(aa_H_13)[2]="Halton_Run"
aa_H_13
## # A tibble: 2 x 2
##   Running_Status Halton_Run
##   <fct>               <int>
## 1 0                     105
## 2 1                     260

Portlands Energy Centre

any(is.na(Dz_13Portland))
## [1] TRUE
sum(is.na(Dz_13Portland))
## [1] 2
colSums(is.na(Dz_13Portland)) 
##                 Date Portlands_2013_Total                    n 
##                    1                    1                    0
nrow(Dz_13Portland)
## [1] 366
Dz_13Portland<-na.omit(Dz_13Portland)
any(is.na(Dz_13Portland))
## [1] FALSE
nrow(Dz_13Portland)
## [1] 365
head(Dz_13Portland)
## # A tibble: 6 x 3
##   Date       Portlands_2013_Total     n
##   <date>                    <dbl> <int>
## 1 2013-01-01                    0    24
## 2 2013-01-02                 7542    24
## 3 2013-01-03                 8191    24
## 4 2013-01-04                    0    24
## 5 2013-01-05                    0    24
## 6 2013-01-06                 4368    24
Portlands_U_Status_13<-cut(Dz_13Portland$Portlands_2013_Total,breaks = c(0,100,50000),labels = c(0,1))
Portlands_U_Status_13<-cbind(Dz_13Portland,Portlands_U_Status_13)
Portlands_U_Status_13[is.na(Portlands_U_Status_13)]=0
#Portlands_U_Status_13

#aa_P_10<-count(Portlands_U_Status_10,"Portlands_U_Status_10")
aa_P_13<-Portlands_U_Status_13 %>% count(Portlands_U_Status_13)
names(aa_P_13)[1]="Running_Status"
names(aa_P_13)[2]="Portland_Run"
aa_P_13
## # A tibble: 2 x 2
##   Running_Status Portland_Run
##   <fct>                 <int>
## 1 0                       166
## 2 1                       199

Greenfield Energy Centre

any(is.na(Dz_13Greenfeild))
## [1] TRUE
sum(is.na(Dz_13Greenfeild))
## [1] 2
colSums(is.na(Dz_13Greenfeild)) 
##           Date GEC_2013_Total              n 
##              1              1              0
nrow(Dz_13Greenfeild)
## [1] 366
Dz_13Greenfeild<-na.omit(Dz_13Greenfeild)
any(is.na(Dz_13Greenfeild))
## [1] FALSE
nrow(Dz_13Greenfeild)
## [1] 365
head(Dz_13Greenfeild)
## # A tibble: 6 x 3
##   Date       GEC_2013_Total     n
##   <date>              <dbl> <int>
## 1 2013-01-01           4708    24
## 2 2013-01-02          14465    24
## 3 2013-01-03          13579    24
## 4 2013-01-04           4273    24
## 5 2013-01-05              0    24
## 6 2013-01-06              0    24
Greenfeild_U_Status_13<-cut(Dz_13Greenfeild$GEC_2013_Total,breaks = c(0,100,50000),labels = c(0,1))
Greenfeild_U_Status_13<-cbind(Dz_13Greenfeild,Greenfeild_U_Status_13)
Greenfeild_U_Status_13[is.na(Greenfeild_U_Status_13)]= 0
#Greenfeild_U_Status_13

#aa_GEC_10<-count(Greenfeild_U_Status_10,"Greenfeild_U_Status_10")
aa_GEC_13<-Greenfeild_U_Status_13 %>% count(Greenfeild_U_Status_13)
names(aa_GEC_13)[1]="Running_Status"
names(aa_GEC_13)[2]="Greenfeild_Run"
aa_GEC_13
## # A tibble: 2 x 2
##   Running_Status Greenfeild_Run
##   <fct>                   <int>
## 1 0                         168
## 2 1                         197

Brighton Beach Generating Station

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

#aa_BB_10<-count(Brighton_U_Status_10,"Brighton_U_Status_10")
aa_BB_13<-Brighton_U_Status_13 %>% count(Brighton_U_Status_13)
names(aa_BB_13)[1]="Running_Status"
names(aa_BB_13)[2]="Brighton_Run"
aa_BB_13
## # A tibble: 2 x 2
##   Running_Status Brighton_Run
##   <fct>                 <int>
## 1 0                       327
## 2 1                        38
U_R_Status_13<-cbind(aa_G_13,aa_H_13[,2],aa_P_13[,2],aa_GEC_13[,2],aa_BB_13[,2])
names(U_R_Status_13)[2]="Goreway"
names(U_R_Status_13)[3]="Halton"
names(U_R_Status_13)[4]="Portlands"
names(U_R_Status_13)[5]="Greenfield"
names(U_R_Status_13)[6]="Brighton"

Barplot

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

ggplot

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

No_Run<-c(U_R_Status_13[1,2],U_R_Status_13[1,3],U_R_Status_13[1,4],U_R_Status_13[1,5],U_R_Status_13[1,6])
Run<-c(U_R_Status_13[2,2],U_R_Status_13[2,3],U_R_Status_13[2,4],U_R_Status_13[2,5],U_R_Status_13[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  186
## 2      Halton  105
## 3   Portlands  166
## 4  Greenfield  168
## 5    Brighton  327
## 6     Goreway  179
## 7      Halton  260
## 8   Portlands  199
## 9  Greenfield  197
## 10   Brighton   38
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()