Commit c069e1bb authored by Ben Anderson's avatar Ben Anderson
Browse files

copied repo from github

This diff is collapsed.
# FEEG6025 Data Analysis & Experimental Methods for Civil and Environmental Engineering (Semester 1 2016-2017)
## Week 1
This folder contains the RMarkdown starter kit or template (week1RMarkdownStarterKit.Rmd) we developed during the practical session. Feel free to use it as a basis for future r code, reports etc. Also included are outputs as .md, .html, .docx and .pdf. These may not look identical due to the way knitr formats them but they have identical content.
If you want to re-use any of the code, read the [License file](!
This diff is collapsed.
# RMarkdown Starter Kit
Ben Anderson
29 September 2016
# This a level 1 Heading
This RMarkdown document is an edited version of the default template that is created by RStudio when you create a new RMarkdown file.
## This is a level 2 Heading
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
## Including Plots
You can also embed plots, for example:
![Old style plot of pressure agianst temperature](week1RMarkdownStarterKit_files/figure-html/oldGraph-1.png)
We can try that again using ggplot2 to draw a prettier graph and a slightly amended pressure data-set read from a web server.
First we will load the data and check what is in the data table.
# ECHO is on (by default) se we can see the code that was run
# NB: this will fail if you do not have an internet connection (obvioulsy!)
# first use the fread function from data.table to load the .csv data from a website into a data table
pressure_DT <- fread("")
# check what's in the data table - there should be two variables
## temperature pressure
## Min. : 0 Min. : 0.0002
## 1st Qu.:100 1st Qu.: 0.2700
## Median :200 Median : 17.3000
## Mean :200 Mean : 200.3046
## 3rd Qu.:300 3rd Qu.: 247.0000
## Max. :400 Max. :1000.0000
Now build the new graph.
# now use ggplot to draw a graph of the new data. We will do this in two steps:
# 1: create the graph 'object'
myGraph <- ggplot(pressure_DT) +
aes(x = temperature, # this is the variable name from the data table that we want on the x axis
y = pressure) # this is the variable we want on the y axis
# 2: draw the graph
![](week1RMarkdownStarterKit_files/figure-html/newGraph-1.png)<!-- -->
Q: Why did we create a graph object and then draw it? A: So that we can add things to the graph object later. For example we can re-use the myGraph object but add a title and better labels:
# draw the graph again but with a new title
myGraph + labs(
title = "Observed relationship between temperature and pressure",
x = "Pressure (unit?)",
y = "Temperature (unit?)"
![](week1RMarkdownStarterKit_files/figure-html/newGraph2-1.png)<!-- -->
ggplot2 supports a wide range of options for manipulating axes, labels, titles, legends etc. The best resource for this is the ggplot2 book or (for the more experienced) the ggplot2 online documentation.
# Notes
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
# Embedding R in your text
This is how you embed R code in your text: 4 = 4 = 8.
We can use that to do helpful things like print the date and time when the code executes:
Code last run at: **2016-10-07 09:34:31**
Or the directory/folder that R thinks we are in:
Current directory: /Users/ben/github/FEEG6025/2016_2017/week_1
Both of these are very useful for checking when you last ran the code that generated the output you are looking at and where the code and the output were saved.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment