---
title: "Flight analysis"
---

This [R Markdown](http://rmarkdown.rstudio.com/) file creates graphs of recorded flight parameters, stored in `flight.csv` via the `monitor.py` Kerbal RPC script.

```{r opts, include=FALSE}
library(knitr)
opts_chunk$set(tidy=TRUE)
```

```{r init}
library(ggplot2)
library(scales)
library(broom)
flight <- read.csv("flight.csv", header=T)
flight$mission_time <- as.POSIXct(flight$mission_time, origin=Sys.Date(), tz="GMT")
flight$orbit_period <- as.POSIXct(flight$orbit_period, origin=Sys.Date(), tz="GMT")
```

Columns:

```{r, echo=FALSE, results="asis"}
cat(paste0("1. ", names(flight)), sep="\n")
```

```{r graph, message=FALSE}
# Graphing logic
baseg <- ggplot(flight, aes(x=mission_time)) + xlab("Time (H:M:S)") + theme_classic() + scale_x_datetime(date_labels="%H:%M:%S") + scale_y_continuous(labels=comma)
alt <- baseg + geom_line(aes(y=current_altitude)) + ylab("Altitude (m)") + ggtitle("Altitude")
vspd <- baseg + geom_line(aes(y=v_speed)) + ylab("Vertical speed (m/s)") + ggtitle("Vertical speed")
hspd <- baseg + geom_line(aes(y=h_speed)) + ylab("Horizontal speed (m/s)") + ggtitle("Horizontal speed")
mass <- baseg + geom_line(aes(y=mass)) + ylab("Vessel mass (kg)") + ggtitle("Mass")
ec <- baseg + geom_line(aes(y=electric_charge)) + ylab("Electric charge") + ggtitle("Electric charge")
lf <- baseg + geom_line(aes(y=liquid_fuel)) + ylab("Liquid fuel (litres)") + ggtitle("Liquid fuel")
ox <- baseg + geom_line(aes(y=oxidizer)) + ylab("Oxidizer (litres)") + ggtitle("Oxidizer")
at <- baseg + geom_line(aes(y=available_thrust)) + ylab("Available thrust (Newtons)") + ggtitle("Available thrust")
thrust <- baseg + geom_line(aes(y=current_thrust)) + ylab("Current thrust (Newtons)") + ggtitle("Current thrust")
g_force <- baseg + geom_line(aes(y=g_force)) + ylab("G-force (m/s²)") + ggtitle("G-force")
ap <- baseg + geom_line(aes(y=apoapsis)) + ylab("Apoapsis altitude (m)") + ggtitle("Apoapsis")
pa <- baseg + geom_line(aes(y=periapsis)) + ylab("Periapsis altitude (m)") + ggtitle("Periapsis")
orad <- baseg + geom_line(aes(y=orbital_radius)) + ylab("Orbital radius (m)") + ggtitle("Orbital radius")
os <- baseg + geom_line(aes(y=orbit_speed)) + ylab("Orbital speed (m/s)") + ggtitle("Orbital speed")
op <- baseg + geom_line(aes(y=orbit_period)) + ylab("Orbital period (H:M:S)") + ggtitle("Orbital period") + scale_y_datetime(date_labels="%H:%M:%S")
```

```{r drawgraphs, echo=FALSE}
alt 
vspd
hspd
mass
ec
lf
ox
at
thrust
g_force
ap
pa
orad
os
op
```
