# load libraries library(ggplot2) #library(tcltk) # read data data <- read.csv("powerbike2.csv") #print first 10 line of data (tail(data, n) for last n lines) head(data, 10) graphics.off() # close all # store theme settings theme_all <- theme(plot.title = element_text(size=20, hjust = 0.5, face="bold"), axis.title.x = element_text(size=14, face="bold"), axis.title.y = element_text(size=14, face="bold")) # Plots in new Window # dev.new() # windows() #Use X11() or quartz() if on linux or mac. # simple ggplot (line plot) ggplot(data, aes(x = Zeit, y = HR)) + # specify data geom_line(color="red", linetype="solid", size=1) + # specify line type ggtitle("Heartrate") + theme(plot.title = element_text(color="red")) + #set title and modify theme xlab("Time (s)") + ylab("Heartrate (bpm)") + # set x- and y-labels theme_all # example with gg as ggplot object # dev.new() gg <- ggplot(data, aes(x = Zeit, y = HR)) gg <- gg + geom_line(color="red", linetype="solid", size=1) print(gg) # dev.new() # windows() ggplot(data, aes(x = Zeit, y = Last)) + geom_line(color="blue", linetype="solid", size=1) + ggtitle("Power") + theme(plot.title = element_text(color="blue")) + xlab("Time (s)") + ylab("Power (W)") + theme_all # dev.new() # windows() # ggplot with two lines ggplot(data, aes(x = Zeit, y = HR)) + geom_line(colour="red", linetype="solid", size=1) + # first line geom_line(aes(x = Zeit, y = Last), colour="blue") + # second line ggtitle("Power and Heartrate") + xlab("Time (s)") + ylab("Power (W) / Heartrate (bpm)") + theme_all # dev.new() # windows() # ggplot with two lines and legend ggplot(data, aes(x = Zeit)) + geom_line(aes(y = HR, color="Heartrate"), size=2) + geom_line(aes(y = Last, color="Power"), size=2, linetype="twodash") + labs(title = "Power and Heartrate", x = "Time (s)", y = "Power (W) / Heartrate (bpm)", color="Measurements") + scale_colour_manual(values = c("Heartrate" = "red", "Power" = "blue")) + #set manual color for the two lines and get legend theme_all + theme(panel.grid.major = element_line(color="grey")) + scale_x_continuous(breaks = round(seq(min(data$Zeit), max(data$Zeit), by = 200), -1)) + # modify x-ticks scale_y_continuous(breaks = round(seq(min(data$Last), max(data$Last), by = 20), 0)) # modify y-ticks # keep plot windows open # wait <- tk_messageBox(message = "Stop", detail = "Now")