Visualizing Electricity in Costa Rica Using a Heat Map

Introduction

We introduced and looked into the Costa Rican Electrical Energy Usage for the October of 2016 in the previous post. We look at the same data set using a heat map made available by the grammar of graphics (ggplot2) library in R. The code and the corresponding results are as follows.

<br />library(plyr)
library(dplyr)
library(plotly)
library(highcharter)
library(lubridate)
library(viridis)
elec <- read.csv("SEN oct-2016.csv",header = T,stringsAsFactors = F)
str(elec)
elec <- filter(elec,Tipo.de.Empresa!="#N/A")
elec <- filter(elec,Tipo.de.Fuente!="#N/A")
#elec$Dia <- paste(elec$Dia,elec$Hora,":00")
elec$Dia <- mdy_hm(paste(elec$Dia,elec$Hora))
elec$day <- wday(elec$Dia,label=T)
library(stringr)
df <- elec %>% group_by(Hora,day,Tipo.de.Empresa,Tipo.de.Fuente) %>% summarise(n=mean(Produccion..MWh.,na.rm=T))
df <- filter(df,n>=0)

p <-ggplot(df,aes(day,Hora,fill=n))+
geom_tile(color= "white",size=0.1) +
scale_fill_viridis(name="Hourly Average Production of Electricty",option ="C")
p <-p + facet_grid(Tipo.de.Empresa~Tipo.de.Fuente)
p <-p + scale_y_continuous(trans = "reverse", breaks = unique(df$Hora))
#p <-p + scale_x_continuous(breaks =c(1,10,20,31))
p <-p + theme_minimal(base_size = 8)
p <-p + labs(title= paste("Average Hourly Production(Positive) By Company Type and Fuel"), x="Day", y="Hour")
p <-p + theme(legend.position = "bottom")+
theme(plot.title=element_text(size = 14))+
theme(axis.text.y=element_text(size=6)) +
theme(strip.background = element_rect(colour="white"))+
theme(plot.title=element_text(hjust=0))+
theme(axis.ticks=element_blank())+
theme(axis.text=element_text(size=7))+
theme(legend.title=element_text(size=8))+
theme(legend.text=element_text(size=6))+
theme(plot.title=element_text(size=18),axis.text.x = element_text(angle=90, vjust=1))
(p)

heat_map.png

The above plot gives us a picture of the average production (day and hour)by company type(private/public) and by fuel type. The y axis takes the role of keeping time in hours.

We see that water based electricity production was higher as was seen in the previous post. Thank You for reading! Feel free to leave your feedback in the comments section below.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s