Beruflich Dokumente
Kultur Dokumente
Graphs
Chapter 4
Prof. Andy Field
Modified by R. L. Tremblay
Review Chapter 3:
The R Environment
You do not have to go through the R
Commander (we will not use this in
this class)
Aims
How to present data clearly
Introduce ggplot2
Graphs
Scatterplots
Histograms
Boxplots
Error bar charts
Line Graphs
Thoughts
Actions
14
12
10
8
6
T h o u g h ts /A c tio
N um ber of O bse
4
2
0
CBT
BT
Therapy
No Treatment
ggplot2
Plot
Plot
Layers
Geoms
Aesthetics
Aesthetic
Data
Colour
Size
Shape
etc.
Specic
e.g.,
"Red"
2
e.g.,
colour = "Red"
linetype =2
Variable
Use aes()
e.g.,
gender,
experimental group
e.g.,
aes(colour =gender),
aes(shape = group)
specifying aesthetics in
ggplot2
Layer/Geom
Plot
Scatterplots: Example
Anxiety and Exam Performance
Participants:
103 students
Measures
Time spent revising (hours)
Exam performance (%)
Exam Anxiety (the EAQ, score out of
100)
Gender
Simple Scatterplot
scatter <- ggplot(examData,
aes(Anxiety, Exam))
scatter + geom_point() +
geom_smooth() +
labs(x = "Exam Anxiety", y = "Exam
Performance %")
Simple Scatterplot
Simple Scatterplot
Grouped Scatterplot
scatter <- ggplot(examData,
aes(Anxiety, Exam, colour = Gender))
scatter + geom_point() +
geom_smooth(method = "lm", aes(fill
= Gender), alpha = 0.1) +
labs(x = "Exam Anxiety", y = "Exam
Performance %", colour = "Gender")
Grouped Scatterplot
Unusual scores
Histograms: Example
A biologist was worried about the
potential health effects of music festivals.
Download Music Festival
Measured the hygiene of 810 concertgoers over the three days of the festival.
Hygiene was measured using a
standardised technique :
Score ranged from 0 to 4
0 = you smell like a corpse rotting
4 = you smell of sweet roses on a fresh spring day
Outliers
6
Rating (out of 5)
1
1
Rater
Slide 26
Boxplots (Box-Whisker
Diagrams)
Boxplots are made up of a box and two
whiskers.
The box shows:
The median
The upper and lower quartile
The limits within which the middle 50% of
scores lie.
The Boxplot
Top 25%
Middle 50%
Median
Bottom 25%
Lower Quartile
Outcome measure
Physiological arousal as an indicator of how
much they enjoyed the film.
Outcome measure
The number of hiccups in the minute after each
procedure
Outcome measure
Percentage score on a grammar test