Trying ggplot, since had some POSIXct x axis problems with RMarkdown

(Edit: got it finally working also with simple plot: http://rpubs.com/rrwiren/377796)
library(ggplot2)

We start with loading some data and attach the data frame for easier access

e20180301 <- read.csv("~/Downloads/energydatamod/2018-03-01_twmod.csv", sep=";")
attach(e20180301)

Always good to explore the data, specially the date and time formats

head(e20180301)
##              Start              End Consumption Status    SPOT Temperature
## 1 2018-03-01 00:00 2018-03-01 01:00        3.44     Ok 4.68224       -16.4
## 2 2018-03-01 01:00 2018-03-01 02:00        4.38     Ok 4.90048       -16.5
## 3 2018-03-01 02:00 2018-03-01 03:00        4.18     Ok 4.84220       -16.9
## 4 2018-03-01 03:00 2018-03-01 04:00        3.79     Ok 4.81492       -16.7
## 5 2018-03-01 04:00 2018-03-01 05:00        4.37     Ok 4.83848       -17.1
## 6 2018-03-01 05:00 2018-03-01 06:00        3.52     Ok 4.91040       -17.7
str(Start)
##  Factor w/ 24 levels "2018-03-01 00:00",..: 1 2 3 4 5 6 7 8 9 10 ...
unclass(Start)
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24
## attr(,"levels")
##  [1] "2018-03-01 00:00" "2018-03-01 01:00" "2018-03-01 02:00"
##  [4] "2018-03-01 03:00" "2018-03-01 04:00" "2018-03-01 05:00"
##  [7] "2018-03-01 06:00" "2018-03-01 07:00" "2018-03-01 08:00"
## [10] "2018-03-01 09:00" "2018-03-01 10:00" "2018-03-01 11:00"
## [13] "2018-03-01 12:00" "2018-03-01 13:00" "2018-03-01 14:00"
## [16] "2018-03-01 15:00" "2018-03-01 16:00" "2018-03-01 17:00"
## [19] "2018-03-01 18:00" "2018-03-01 19:00" "2018-03-01 20:00"
## [22] "2018-03-01 21:00" "2018-03-01 22:00" "2018-03-01 23:00"

We change this here because dates and times are actually stored as factors

dateTime <- as.POSIXlt(Start)
str(dateTime)
##  POSIXlt[1:24], format: "2018-03-01 00:00:00" "2018-03-01 01:00:00" ...
unclass(dateTime)
## $sec
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 
## $min
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 
## $hour
##  [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## [24] 23
## 
## $mday
##  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## 
## $mon
##  [1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## 
## $year
##  [1] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
## [18] 118 118 118 118 118 118 118
## 
## $wday
##  [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
## 
## $yday
##  [1] 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
## [24] 59
## 
## $isdst
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 
## $zone
##  [1] "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET"
## [12] "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET" "EET"
## [23] "EET" "EET"
## 
## $gmtoff
##  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [24] NA

We start with plotting the hourly Consumption data

p <- ggplot(e20180301, aes(x = dateTime))
p <- p + geom_line(aes(y = Consumption))

Then we add Temperature

p <- p + geom_line(aes(y = Temperature))
p

Next we continue and create the plot with two data variables

Again we start by plotting the Consumption

p <- ggplot(e20180301, aes(x = dateTime))
p <- p + geom_line(aes(y = Consumption, colour = "Consumption"))

Here we add the Temperature, transformed to match roughly the range of the Consumption

p <- p + geom_line(aes(y = Temperature/3, colour = "Temperature"))
Now adding the secondary axis, following the example in the help file ?scale_y_continuous
and, very important, reverting the above transformation
p <- p + scale_y_continuous(sec.axis = sec_axis(~.*3, name = "Temepertaure (°C)"))

Modifying colours and theme options

p <- p + scale_colour_manual(values = c("blue", "red"))
p <- p + labs(y = "Consumption (kWh)",
              x = "Date and time",
              colour = "Parameter")
p <- p + theme(legend.position = c(0.8, 0.9))
p

This page is hopefully just a start in a series of many as part of my learning journey

My aim is to add more similar things over time to grow a collection that can be re-used easily

This was inspired by this page: https://rpubs.com/MarkusLoew/226759