forked from CrumpLab/LabJournalWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.Rmd
More file actions
134 lines (104 loc) · 3.12 KB
/
examples.Rmd
File metadata and controls
134 lines (104 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
title: "GG-Plot Exercises"
output:
html_document:
toc: true
toc_float: true
collapsed: false
number_sections: false
toc_depth: 1
#code_folding: hide
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(message=FALSE,warning=FALSE, cache=TRUE)
```
##Examples for how to turn data into different graphs
###1. Example of line graph
Two conditions and Two different lines to indicate significance
```{r}
library(ggplot2)
# add "each" to keep both copies of the names together
Names <- rep(c("Dara","Azalea","Barbi","Rowena","Fiona","Katie","Liza","Rita"),each=2)
MF <- rnorm(16,50,25)
Condition <-rep(c("Social","Nonsocial"),8)
# "times=" to repeat how many times you want A and N_A to be repeated
Aversity <- rep(c("A","N_A"),times=c(8,8))
plot_df<- data.frame(Names, MF, Condition)
ggplot(plot_df, aes(x=Condition, y=MF, group=Names,
linetype=Aversity))+
geom_line()+
geom_text(label=Names)+
theme_classic()
```
###2. ScatterPlot with a Regression Line
```{r}
AvNonRisk <- rnorm(8,40,2)
AvSocialRisk <- rnorm(8,40,2)
plot_df <- data.frame(AvNonRisk,AvSocialRisk)
ggplot(plot_df, aes(x=AvNonRisk,y=AvSocialRisk))+
geom_point()+
geom_point(size=2)+
geom_smooth(method=lm)+
xlab("Average Frequency Non Social Risk")+
ylab("Average Frequency Social Risk")+
ggtitle("Scatterplot with Regression")+
theme_classic(base_size=12)+
theme(plot.title = element_text(hjust = 0.5))
```
###2.Bar Graphs
```{r}
library(ggplot2)
#Create a dataframe
factor_one <- rep(as.factor(c("Fill","Empty")),2)
factor_two <- rep(as.factor(c("Wide Base","Wide Top")),2)
dv_means <- c(19.5,17.5,18.5,18)
plot_df <- data.frame(factor_one,
factor_two,
dv_means)
ggplot(plot_df, aes(x=factor_one,y=dv_means,
group=factor_two,
color=factor_two))+
geom_bar(stat="identity",position = "dodge")+
xlab("First factor")+
ylab("Estimate(xids)")+
ggtitle("Two Factor Bar Graph")+
theme_classic(base_size=12)+
theme(plot.title = element_text(hjust = 0.5))
```
###Line Graph
```{r}
factor_one <-c(-25,-8,8,25)
dv_means <- c(4.7,4.9,5,5.3)
dv_SEs <- c(.5,.4,.3,.3)
plot_df <- data.frame(factor_one,
dv_means,
dv_SEs)
# basic line graph
ggplot(plot_df, aes(x=factor_one,y=dv_means, group=1))+
geom_point()+
geom_line()+
geom_errorbar(aes(ymin=dv_means-dv_SEs,
ymax=dv_means+dv_SEs),
width=.2)+
coord_cartesian(ylim=c(4,6))+
xlab("Manipulation (%)")+
ylab("Mean rating")+
ggtitle("Male Faces")+
theme_classic(base_size=12)+
theme(plot.title = element_text(hjust = 0.5))
```
###Make a Histogram
```{r}
score <- rnorm(152,0,1)
n <- 1:152
plot_df <- data.frame(score,n)
ggplot(plot_df, aes(x=score))+
geom_histogram(bins=15,
color="white")+
coord_cartesian(ylim=c(0,40))+
xlab("Log Likleyhood ratio")+
ylab("Participants in each condition")+
ggtitle("Man Performed Surgery n=152")+
theme_classic(base_size=12)+
theme(plot.title = element_text(hjust = 0.5))
```