-
Notifications
You must be signed in to change notification settings - Fork 94
/
percept.R
102 lines (95 loc) · 3.78 KB
/
percept.R
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
#Import files, load plot and data packages, fire up the number machine.
# setwd("~/Dropbox/R/Perceptions of Probability")
probly <- read.csv("probly.csv", stringsAsFactors=FALSE)
numberly <- read.csv("numberly.csv", stringsAsFactors=FALSE)
library(tidyverse)
library(ggjoy)
library(scales)
#Melt data into column format.
numberly <- gather(numberly, "variable", "value", 1:10)
numberly$variable <- gsub("[.]"," ",numberly$variable)
probly <- gather(probly, "variable", "value", 1:17)
probly$variable <- gsub("[.]"," ",probly$variable)
probly$value<-probly$value/100 # convert to %
#Order in the court!
probly$variable <- factor(probly$variable,
c("Chances Are Slight",
"Highly Unlikely",
"Almost No Chance",
"Little Chance",
"Probably Not",
"Unlikely",
"Improbable",
"We Doubt",
"About Even",
"Better Than Even",
"Probably",
"We Believe",
"Likely",
"Probable",
"Very Good Chance",
"Highly Likely",
"Almost Certainly"))
numberly$variable <- factor(numberly$variable,
c("Hundreds of",
"Scores of",
"Dozens",
"Many",
"A lot",
"Several",
"Some",
"A few",
"A couple",
"Fractions of"))
#Modify Theme:
source("ztheme.R")
#Plot probability data
ggplot(probly,aes(variable,value))+
geom_boxplot(aes(fill=variable),alpha=.5)+
geom_jitter(aes(color=variable),size=3,alpha=.2)+
scale_y_continuous(breaks=seq(0,1,.1), labels=scales::percent)+
guides(fill=FALSE,color=FALSE)+
labs(title="Perceptions of Probability",
x="Phrase",
y="Assigned Probability",
caption="created by /u/zonination")+
coord_flip()+
z_theme()
ggsave("plot1.png", height=8, width=8, dpi=120, type="cairo-png")
#Plot numberly data
ggplot(numberly,aes(variable,value))+
geom_boxplot(aes(fill=variable),alpha=0.5)+
geom_jitter(aes(color=variable),size=3,alpha=.2)+
scale_y_log10(labels=trans_format("log10",math_format(10^.x)),
breaks=10^(-2:6))+
guides(fill=FALSE,color=FALSE)+
labs(title="Perceptions of Probability",
x="Phrase",
y="Assigned Number",
caption="created by /u/zonination")+
coord_flip()+
z_theme()
ggsave("plot2.png", height=5, width=8, dpi=120, type="cairo-png")
# Joyplot for probly
ggplot(probly,aes(y=variable,x=value))+
geom_joy(scale=4, aes(fill=variable), alpha=3/4)+
scale_x_continuous(breaks=seq(0,1,.1), labels=scales::percent)+
guides(fill=FALSE,color=FALSE)+
labs(title="Perceptions of Probability",
y="",
x="Assigned Probability",
caption="created by /u/zonination")+
z_theme()
ggsave("joy1.png", height=8, width=8, dpi=120, type="cairo-png")
#Joyplot for numberly
ggplot(numberly,aes(y=variable,x=value))+
geom_joy(aes(fill=variable, alpha=3/4))+
scale_x_log10(labels=trans_format("log10",math_format(10^.x)),
breaks=10^(-2:6))+
guides(fill=FALSE,color=FALSE)+
labs(title="Perceptions of Probability",
x="Assigned Number",
y="",
caption="created by /u/zonination")+
z_theme()
ggsave("joy2.png", height=5, width=8, dpi=120, type="cairo-png")