Language:EN
Pages: 13
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
box plot command ggplot geom package basic ggplot

Box plot command ggplot geom package basic ggplot

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

BIOSTATS'640'–'Spring'2018'
Introduction'to'R'and'R-Studio'
Data'Description'

Page!

1. !Start!of!Session!!………………………………………………………………………………………………………………………………………….!

a. 'Preliminaries''…………………………………………………………………………………………………………….……………………………..' b. Install'Packages''…………………………………………………………………………………………………………………………………………' Attach'Packages''………………………………………………………………………………………………………………………………………...' c.

4. SINGLE!VARIABLE!-!Continuous………………………………………………………………………………………………………………….!
a.
b. . '''Graphical'…………………………………………………………………………………………………………………………………………………'

'
5. TWO!VARIABLES!–!One!Continuous,!One!Discrete!!…………………………………………………………………………………….!

a.'''Numerical''………………………………………………………………………………………………………………….……………………' b.'Graphical'…………………………………………………………………………………………………………………………………………………' '
6. TWO!VARIABLES!–!BOTH!Continuous!!…………………………………………………………………………..………………………….!

2!

2!

!

5!

7!

7!

!

13!
13!

'

# 1. START OF SESSION '
# 1a. Preliminaries'
# setwd( ) to set working directory'
# Tips: 1) R wants forward slashes and 2) must enclose in quotes' setwd("/Users/cbigelow/Desktop/")'
# 1b. Clear workspace '
rm(list=ls())'
# 1c. Turn OFF scientific notation'
options(scipen=1000)'

library(DescTools)
library(psych)'

library(ggplot2)

2. Load R Data!

# 2b. Check

# str(DATAFRAME) to check structure of dataframe'
str(ivf)'

# tail(DATAFRAME) to display last 6 rows'
tail(ivf)'

## id matage hyp gestwks sex bweight' ## 636 636 34 0 41.15 male 2972' ## 637 637 28 0 38.58 female 2850' ## 638 638 38 1 38.44 male 3182' ## 639 639 26 0 38.94 female 3048' ## 640 640 31 0 40.43 female 3183' ## 641 641 31 0 38.15 male 2920'

R'Data'Description'II'Spring'2018.docx''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Page 4 of 13'

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

3.SINGLE VARIABLE - DISCRETE

## level freq perc cumfreq cumperc'

## 1 male 326 50.9% 326 50.9%'

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

# With aesthetics: I recommend building step by step, then displaying!' p <-ggplot(data=ivf, aes(x=factor(hyp)))'
p1 <-p +geom_bar(color="black", fill="blue")'
p2 <-p1 +xlab("Hypertension") '
p3 <-p2 +ylab("Frequency")'
p4 <-p3 +ggtitle("Bar Graph of Hypertension")'
p5 <-p4 +theme_bw()'
p5'

'

R'Data'Description'II'Spring'2018.docx''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Page 6 of 13'

# 4a.2. Quantiles'
# Command quantile() in package=mosaic' quantile(~bweight, data=ivf)'

## 0% 25% 50% 75% 100% '
## 630 2850 3200 3550 4650'

# 4b. Graphical'
# 4b.1. Box plot'
# Command ggplot() + geom_boxplot() in package=ggplot2' # Basic'
ggplot(data=ivf, aes(x=1, y=matage)) +geom_boxplot() '

'

# 4b.2 Histogram'
# Command ggplot() + geom_histogram() in package=ggplot2' # Basic'
ggplot(data=ivf, aes(x=matage)) +geom_histogram() '

## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.'

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

# With aesthetics - step by step'
p18 <-ggplot(data=ivf, aes(x=matage)) +geom_histogram(color="black", fill="blue", binwidth=2)' p19 <-p18 +xlab("Maternal Age (years)")'
p20 <-p19 +ylab("Frequency")'
p21 <-p20 +ggtitle("Histogram of Maternal Age")'
p22 <-p21 +theme_bw()'
p22'

!

# 5. TWO VARIABLES - ONE CONTINUOUS, ONE DISCRETE'
# 5a. Numerical'
# 5a.1. Detailed descriptives, by group'
# Command describeBy() in package=psych'
# Tip - Declare your discrete group variable to be factor' library(psych)'
ivf$sex <-as.factor(ivf$sex)'
describeBy(ivf$bweight, group = ivf$sex,digits=4)'

R'Data'Description'II'Spring'2018.docx''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Page 10 of 13'

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

'

R'Data'Description'II'Spring'2018.docx''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Page 11 of 13'

'

# 5b.3. Histogram, by group - Overlay '
# Command ggplot() + geom_histogram() in package=ggplot2' # With aesthetics - step by step'

BIOSTATS'640'–'Spring'2018'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Introduction'to'R'–'Data'Description'

p32 <-p31 +theme_bw()

p32

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Jane Cruz

PageId: ELIA13A1D4