Accelerometer for different activity Example

We can make this program using looping if we have many of data, but in this document I change the variable name manualy because we only have 4 data.

Data : Enter room

Set dir and load library

setwd("C:/Users/rischan/Dropbox/RESEARCH/magno/data/cam")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.1.1
library(scales)

Load the data

denter <- read.csv("Enter.csv")
denter <- data.frame(denter$ACCELEROMETER.X..m.s².,denter$ACCELEROMETER.Y..m.s².,
                     denter$ACCELEROMETER.Z..m.s².,denter$MAGNETIC.FIELD.X..Î.T.,
                     denter$MAGNETIC.FIELD.Y..Î.T.,denter$MAGNETIC.FIELD.Z..Î.T.,
                     denter$YYYY.MO.DD.HH.MI.SS_SSS)

names(denter) <- c("accX","accY","accZ","mX","mY","mZ","time")
denter$time <- strptime(gsub(":(?!\\d+:)", ".", as.character(denter$time), perl=T), "%Y-%m-%d %H:%M:%OS")

Acc Plot

#Accelerometer dEnter

p <- ggplot(denter, aes(denter$time, denter$accX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer X")
p

plot of chunk unnamed-chunk-3

p <- ggplot(denter, aes(denter$time, denter$accY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Y")
p

plot of chunk unnamed-chunk-3

p <- ggplot(denter, aes(denter$time, denter$accZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Z")
p

plot of chunk unnamed-chunk-3

Magno Plot

p <- ggplot(denter, aes(denter$time, denter$mX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno X")
p

plot of chunk unnamed-chunk-4

p <- ggplot(denter, aes(denter$time, denter$mY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Y")
p

plot of chunk unnamed-chunk-4

p <- ggplot(denter, aes(denter$time, denter$mZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("5 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Z")
p

plot of chunk unnamed-chunk-4

Data : Sit down

Load the data

dsit <- read.csv("Sit.csv")
dsit <- data.frame(dsit$ACCELEROMETER.X..m.s².,dsit$ACCELEROMETER.Y..m.s².,
                   dsit$ACCELEROMETER.Z..m.s².,dsit$MAGNETIC.FIELD.X..Î.T.,
                   dsit$MAGNETIC.FIELD.Y..Î.T.,dsit$MAGNETIC.FIELD.Z..Î.T.,
                   dsit$YYYY.MO.DD.HH.MI.SS_SSS)

names(dsit) <- c("accX","accY","accZ","mX","mY","mZ","time")
dsit$time <- strptime(gsub(":(?!\\d+:)", ".", as.character(dsit$time), perl=T), "%Y-%m-%d %H:%M:%OS")

Acc Plot

#Accelerometer dSit

p <- ggplot(dsit, aes(dsit$time, dsit$accX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer X")
p

plot of chunk unnamed-chunk-6

p <- ggplot(dsit, aes(dsit$time, dsit$accY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Y")
p

plot of chunk unnamed-chunk-6

p <- ggplot(dsit, aes(dsit$time, dsit$accZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Z")
p

plot of chunk unnamed-chunk-6

Magno Plot

#Magno dsit

p <- ggplot(dsit, aes(dsit$time, dsit$mX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno X")
p

plot of chunk unnamed-chunk-7

p <- ggplot(dsit, aes(dsit$time, dsit$mY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Y")
p

plot of chunk unnamed-chunk-7

p <- ggplot(dsit, aes(dsit$time, dsit$mZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Z")
p

plot of chunk unnamed-chunk-7

Data : Stand

Load the data

dstand <- read.csv("Stand.csv")
dstand <- data.frame(dstand$ACCELEROMETER.X..m.s².,dstand$ACCELEROMETER.Y..m.s².,
                     dstand$ACCELEROMETER.Z..m.s².,dstand$MAGNETIC.FIELD.X..Î.T.,
                     dstand$MAGNETIC.FIELD.Y..Î.T.,dstand$MAGNETIC.FIELD.Z..Î.T.,
                     dstand$YYYY.MO.DD.HH.MI.SS_SSS)

names(dstand) <- c("accX","accY","accZ","mX","mY","mZ","time")
dstand$time <- strptime(gsub(":(?!\\d+:)", ".", as.character(dstand$time), perl=T), "%Y-%m-%d %H:%M:%OS")

Acc Plot

p <- ggplot(dstand, aes(dstand$time, dstand$accX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer X")
p

plot of chunk unnamed-chunk-9

p <- ggplot(dstand, aes(dstand$time, dstand$accY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Y")
p

plot of chunk unnamed-chunk-9

p <- ggplot(dstand, aes(dstand$time, dstand$accZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Z")
p

plot of chunk unnamed-chunk-9

Magno Plot

p <- ggplot(dstand, aes(dstand$time, dstand$mX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno X")
p

plot of chunk unnamed-chunk-10

p <- ggplot(dstand, aes(dstand$time, dstand$mY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Y")
p

plot of chunk unnamed-chunk-10

p <- ggplot(dstand, aes(dstand$time, dstand$mZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Z")
p

plot of chunk unnamed-chunk-10

Data : Walk

Load the data

dwalk <- read.csv("Walk.csv")
dwalk <- data.frame(dwalk$ACCELEROMETER.X..m.s².,dwalk$ACCELEROMETER.Y..m.s².,
                    dwalk$ACCELEROMETER.Z..m.s².,dwalk$MAGNETIC.FIELD.X..Î.T.,
                    dwalk$MAGNETIC.FIELD.Y..Î.T.,dwalk$MAGNETIC.FIELD.Z..Î.T.,
                    dwalk$YYYY.MO.DD.HH.MI.SS_SSS)

names(dwalk) <- c("accX","accY","accZ","mX","mY","mZ","time")
dwalk$time <- strptime(gsub(":(?!\\d+:)", ".", as.character(dwalk$time), perl=T), "%Y-%m-%d %H:%M:%OS")

Acc Plot

p <- ggplot(dwalk, aes(dwalk$time, dwalk$accX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer X")
p

plot of chunk unnamed-chunk-12

p <- ggplot(dwalk, aes(dwalk$time, dwalk$accY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Y")
p

plot of chunk unnamed-chunk-12

p <- ggplot(dwalk, aes(dwalk$time, dwalk$accZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Accelerometer Z")
p

plot of chunk unnamed-chunk-12

Magno Plot

p <- ggplot(dwalk, aes(dwalk$time, dwalk$mX)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno X")
p

plot of chunk unnamed-chunk-13

p <- ggplot(dwalk, aes(dwalk$time, dwalk$mY)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Y")
p

plot of chunk unnamed-chunk-13

p <- ggplot(dwalk, aes(dwalk$time, dwalk$mZ)) +
     geom_line() + scale_x_datetime(breaks=date_breaks("15 sec"), labels = date_format("%H:%M:%S")) + xlab("Time") +
     ylab("Magno Z")
p

plot of chunk unnamed-chunk-13