# This plots the first 25 seconds of readings from four different
# parts of the head, for one subject, coloured to show the labels
# that we're meant to forecast.

library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)

train10_1 = read_csv('../input/train/subj10_series1_data.csv')
events10_1 = read_csv("../input/train/subj10_series1_events.csv")

first25seconds = cbind(train10_1[1:12500,], events10_1[1:12500,] %>%
                    select(-id)) %>% mutate(Event = "Nothing")
first25seconds$Event[first25seconds$HandStart==1] = "HandStart"
first25seconds$Event[first25seconds$FirstDigitTouch==1] = "FirstDigitTouch"
first25seconds$Event[first25seconds$BothStartLoadPhase==1] = "BothStartLoadPhase"
first25seconds$Event[first25seconds$LiftOff==1] = "LiftOff"
first25seconds$Event[first25seconds$Replace==1] = "Replace"
first25seconds$Event[first25seconds$BothReleased==1] = "BothReleased"
first25seconds$Event = factor(first25seconds$Event,
                            levels=c("Nothing", "HandStart", "FirstDigitTouch", "BothStartLoadPhase",
                                "LiftOff", "Replace", "BothReleased"))
first25seconds$Time = 1:12500


plotData = first25seconds %>% select(Time, Event, T7, T8, Fp1, O2) %>% gather(Location, Value, T7:O2)

ggplot(plotData) + aes(x=Time, y=Value) + geom_point(size=1, colour="grey") +
        geom_point(aes(colour=Event), data=plotData %>% filter(Event != "Nothing")) + facet_wrap(~Location)
