library(fda) #library(ggplot2) # example of functional data handpart <- handwrit[1:200,1:6,1] handwritTimepart <- handwritTime[1:200] x11() matplot(handwritTimepart, handpart, pch = 1, xlab = "Time [ms]", ylab = "Position [mm]") # ggplot # dfpart <- data.frame(time = handwritTimepart, sx = c(handpart), # sample = factor(rep(1:6, each = length(handwritTimepart)))) # # p <- ggplot(dfpart, aes(x = time, y = sx, colour = sample, group = sample)) # p <- p + geom_point(size = 0.5) # p <- p + labs (x = "Time [ms]", y = "Position [mm]") # p <- p + theme_bw () # print (p) # example of functional data - all the series handpart <- handwrit[,1:6,1] matplot(handwritTime, handpart, pch = 1, xlab = "Time [ms]", ylab = "Position [mm]") # ggplot # dfX <- data.frame(time = handwritTime, sx = c(handpart), # sample = factor(rep(1:6, each = length(handwritTime)))) # # p <- ggplot(dfX, aes(x = time, y = sx, colour = sample, group = sample)) # p <- p + geom_point(size = 0.5) # p <- p + labs (x = "Time [ms]", y = "Position [mm]") # p <- p + theme_bw () # print (p) # X-axis and Y-axis separately handpartx <- handwrit[,1:6,1] handparty <- handwrit[,1:6,2] par(mfrow = c(2,1)) matplot(handwritTime, handpartx, pch = 1, xlab = "Time [ms]", ylab = "Position [mm]") matplot(handwritTime, handparty, pch = 1, xlab = "Time [ms]", ylab = "Position [mm]") # ggplot # dfx <- data.frame(time = handwritTime, sx = c(handwrit[, 1:6, 1]), coord = "X(t)", # sample = factor(rep(1:6, each = length(handwritTime)))) # # dfy <- data.frame(time = handwritTime, sx = c(handwrit[, 1:6, 2]), coord = "Y(t)", # sample = factor(rep(1:6, each = length(handwritTime)))) # # df <- rbind(dfx, dfy) # # p <- ggplot(df, aes(x = time, y = sx, colour = sample, group = sample)) # p <- p + geom_line() # p <- p + facet_grid(coord ~ .) # p <- p + labs (x = "Time [ms]", y = "Position [mm]") # p <- p + theme_bw () # print (p) # X-axis and Y-axis simultaneously matplot(handpartx, handparty, pch = 1) # ggplot # df <- data.frame(time = handwritTime, sx = c(handwrit[, 1:6, 1]), sy = c(handwrit[, 1:6, 2]), # sample = factor(rep(1:6, each = length(handwritTime)))) # # # p <- ggplot(df, aes(x = sx, y = sy, colour = sample, group = sample)) # p <- p + geom_path() # p <- p + labs (x = "Position [mm]", y = "Position [mm]") # p <- p + theme_bw () # print (p) # ------------------ # Problems # ------------------ # 1. install.packages("fda") # 2. Berkeley Growth Data ?growth # 3. Canadian Weather Data ?CanadianWeather