library("R.matlab") library("plotly") source("computePower.R") segment <- R.matlab::readMat("segment.mat") segment <- segment[[1]] distance <- segment[[1]][1,] altitude <- segment[[2]][1,] slope <- segment[[3]][1,] p <- plot_ly() %>% add_lines(x = distance, y = altitude, name = "Höhe (m)", line = list(color="red")) %>% add_lines(x = distance, y = slope*100, name = "Steigung (%)", yaxis = "y2", line = list(color="blue")) %>% layout( showlegend = FALSE, margin = list(t = 50), title = "Höhe und Steigung", font=list(size=20), xaxis = list(showline = TRUE, title="Distance (m)", titlefont = list(size=18)), yaxis = list(range = c(100,450),linecolor = toRGB("red"), title="Höhe (m)", tickfont = list(color = "red"), titlefont = list(color="red", size=18)), yaxis2 = list(range = c(1,8), linecolor = toRGB("blue"),showline = TRUE, automargin = TRUE, title="Steigung (%)",side="right", tickfont = list(color = "blue"), titlefont = list(color="blue", size=18), overlaying="y") ) print(p) speed <- read.csv("speed.csv", header=FALSE) speed1 <- as.numeric(speed[1,]) power <- computePower(distance,speed1,altitude,80) p <- plot_ly() %>% add_lines(x = distance, y = speed1*3.6, name = "Speed", line = list(color="red")) %>% add_lines(x = distance, y = power, name = "Power", yaxis = "y2", line = list(color="blue")) %>% layout( showlegend = FALSE, margin = list(t = 50), title = "Power and Speed", font=list(size=20), xaxis = list(showline = TRUE, title="Distance (m)", titlefont = list(size=18)), yaxis = list(linecolor = toRGB("red"),range=c(10,20), title="Speed (km/h)", tickfont = list(color = "red"), titlefont = list(color="red", size=18)), yaxis2 = list(linecolor = toRGB("blue"),showline = TRUE, automargin = TRUE, range=c(50,300), title="Power (W)",side="right", tickfont = list(color = "blue"), titlefont = list(color="blue", size=18), overlaying="y") ) print(p)