Not exactly the same but pretty similar:
Code:
datos_tem <-
read.csv(text=
'datetime,temperature,humidity,dpv
"2014-02-15 00:00:00",67.2,13.6,"red"
"2014-02-15 00:15:00",63.4,13.8,"yellow"
"2014-02-15 00:30:00",61.2,14.2,"green"
"2014-02-15 00:45:00",60.4,14.5,"green"')
datos_tem$datetime <- as.POSIXct(datos_tem$datetime)
datos_tem$temperature <- as.numeric(datos_tem$temperature)
datos_tem$humidity <- as.numeric(datos_tem$humidity)
datos_tem$dpv <- as.character(datos_tem$dpv)
par(mar=c(5,4,4,5)+0.1)
# add temperature
plot(datos_tem$datetime,datos_tem$temperature,typ='b',col='red',
ylab='Temperature',xlab='Time')
# add humidity
par(new=T)
plot(datos_tem$datetime,datos_tem$humidity,type='b',
col='blue',xaxt='n',yaxt='n',xlab='',ylab='')
axis(4)
mtext(side=4,text='Humidity',line=3)
# add colored bars
par(new=T)
xToler <- min(diff(datos_tem$datetime)) / 2
yToler <- (min(datos_tem$humidity) - par('usr')[3]) / 2
enc <- rle(datos_tem$dpv)
idx <- 1
for(i in 1:length(enc$lengths)){
start <- datos_tem$datetime[idx] - xToler
end <- datos_tem$datetime[idx + enc$lengths[i] - 1] + xToler
rect(xleft=start,xright=end,
ybottom=par('usr')[3],ytop=par('usr')[3]+yToler,col=enc$values[i])
idx <- idx + enc$lengths[i]
}
Note:
The code is pretty generic, i.e. it automatically computes positions according to the data in the original "datos_tem" data.frame
.