knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(gcookbook)

R Markdown homework

This is my second R markdown creation! I simply running some graphs examples from the “R-cookbook” and explaining what the data means.

Here we have a data set up people’s ages, sex, weight, and height.

##  sex        ageYear         ageMonth        heightIn        weightLb    
##  f:111   Min.   :11.58   Min.   :139.0   Min.   :50.50   Min.   : 50.5  
##  m:125   1st Qu.:12.33   1st Qu.:148.0   1st Qu.:58.73   1st Qu.: 85.0  
##          Median :13.58   Median :163.0   Median :61.50   Median :100.5  
##          Mean   :13.67   Mean   :164.1   Mean   :61.34   Mean   :101.0  
##          3rd Qu.:14.83   3rd Qu.:178.0   3rd Qu.:64.30   3rd Qu.:112.0  
##          Max.   :17.50   Max.   :210.0   Max.   :72.00   Max.   :171.5

I am going to invetigate the relationship of heigh and age. And fit a linear model to my data.

ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point() + stat_smooth(method=lm)

sp <- ggplot(heightweight, aes(x=ageYear, y=heightIn))

This data set describes the height and weight of people and investigates the relationship between these two variables and age.

Other Plots

The first graph is a simple linear model of the relationship fo height (measured in inches) with age (measured in years).

But perhaps we want to more clearly specify our confidence region? Or we don’t want to show the confidence region at all?

sp <- ggplot(heightweight, aes(x=ageYear, y=heightIn))
#99% confidence region
sp + geom_point() + stat_smooth(method=lm, level=0.99)

#No confidence Region
sp + geom_point() + stat_smooth(method=lm, se=FALSE)

Likewise we could add a non-linear line of best fit, since it is intuitive that people grow more in their earlier years than later.

sp <- ggplot(heightweight, aes(x=ageYear, y=heightIn))
sp + geom_point(colour="grey60") + stat_smooth()
## `geom_smooth()` using method = 'loess'

R-Markdown is super cool tool! I definitely want to learn more.