---
title: "Simple Plots"
output: html_notebook
---
## Powerbike Software Data
#### Read data
```{r}
data <- read.csv("powerbike.csv")
#print(data)
head(data,10)
```
see also [R Manual: read.table](http://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html)
#### Plot data
```{r}
# data[,n] gives nth column
plot(data[,3],data[,6]) # Scatterplot
```
```{r}
plot(data[,3],data[,6],'l') # Lineplot
# plot('l', data[,6], data[,3]) # error
# plot(x = data[,3], y = data[,6], type = 'l') # same as above 27
#plot(type = 'l', y = data[,6], x = data[,3]) # same as above
```
__type__ takes the value "p" to draw only the points, "l" to draw only the lines and "o" to draw both points and lines
## ggplot2
Part of [Tidyverse](https://www.tidyverse.org/) (R packages for data science)
```{r}
#install.packages("ggplot2")
library(ggplot2)
# qplot(data[,3],data[,6],geom = "path") # Quickplot: shortcut for ggplot2
ggplot(data, aes(x = Time, y = Power)) + geom_line()
```
## Colored
```{r}
plot(data[,3],data[,6], type = "l", col = "red", xlab = "Time", ylab = "Power", main = "Powerbike Data")
```
```{r}
ggplot(data, aes(x = Time, y = Power)) +
#geom_line(color="red", linetype="solid", size=2) +
geom_point(color="red", size=1, shape=21, fill="white")
```
## [Plotly](https://plot.ly/r/)
```{r}
#install.packages("plotly")
library(plotly)
plot_ly(x =data[,3],y =data[,6],type = "scatter" ,mode = "lines")
#plot_ly(x =data[,3],y =data[,6],type = "scatter" ,mode = "markers")
```
```{r}
p <- plot_ly(data, x = ~Time, y = ~Power, type = 'scatter', mode = 'lines')
p
```
### ggplot2 with plotly
```{r}
gg <- ggplot(data, aes(x = Time, y = Power)) +
#geom_line(color="red", linetype="solid", size=2) +
geom_point(color="red", size=1, shape=21, fill="white")
ggplotly(gg)
```