Repository navigation
Expand file tree
/
Copy pathmakePlotsNGM.R
More file actions
156 lines (130 loc) · 6.61 KB
/
Copy pathmakePlotsNGM.R
File metadata and controls
156 lines (130 loc) · 6.61 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#########################
#########################
## Spencer Caplan
#########################
#########################
#########################
#########################
## Import (packages)
#########################
#########################
suppressMessages(library(ggplot2))
suppressMessages(library(dplyr))
suppressMessages(library(tidyr))
suppressMessages(library(forcats))
#########################
#########################
## Define auxiliary functions
#########################
#########################
makePlot <- function(currData,outputname,currtitle) {
currPlot <- ggplot(currData,aes(x=GeneralizationLevel, y=Prop, fill=source))+
stat_summary(fun.y=mean, geom='bar',pos='dodge', width = 0.6)+
theme(plot.title = element_text(size=42,face = "bold"), # plot title
legend.title = element_text(size=36, face="bold"), # legend title
axis.title.x = element_text(size=36,angle=0,hjust=.5,vjust=0,face="bold"), # x-axis title
axis.title.y = element_text(size=36,angle=90,hjust=.5,vjust=.5,face="bold"), # y-axis title
legend.text = element_text(size = 36, face = "plain"), # legend text
axis.text.x = element_text(size=36,angle = 40,colour="grey20",hjust=1,face="plain"),
legend.position="none")+ # x-axis text
scale_fill_manual(values=c("orange3","grey31"),name="Source",labels=c("Human","NGM"))+ # fill colour and text
geom_errorbar(aes(ymin=lowerError, ymax=upperError), width=.3, size=.5,position=position_dodge(.6))+
ylim(0.0, 1.0)+
labs(y="Mean Selections",x="Generalization Set", title = currtitle)
ggsave(outputname, width=13.5, height=9, units="in")
}
#########################
#########################
## Read in data
#########################
#########################
workingDir = ''
outputDir = ''
ngmOutputFile = ''
spssMeansFile = 'SPSS_Results_Means.csv'
spssStdDevFile = 'SPSS_Results_StdDev.csv'
## Parse input args
args = commandArgs(trailingOnly=TRUE)
if (length(args)>4) {
workingDir = args[1]
outputDir = args[2]
ngmOutputFile = args[3]
spssMeansFile = args[4]
spssStdDevFile = args[5]
}
setwd(workingDir)
ngmOutputDataRaw = read.csv(ngmOutputFile,header=T,stringsAsFactors=FALSE)
spssMeansData = read.csv(spssMeansFile,header=T,stringsAsFactors=FALSE)
spssStdDevData = read.csv(spssStdDevFile,header=T,stringsAsFactors=FALSE)
ngmOutputMean <- aggregate(cbind(Single, Sub_seq, Basic_seq, Super_seq, Sub_par, Basic_par, Super_par) ~ Proportion, ngmOutputDataRaw, mean)
ngmOutputSD <- aggregate(cbind(Single, Sub_seq, Basic_seq, Super_seq, Sub_par, Basic_par, Super_par) ~ Proportion, ngmOutputDataRaw, sd)
# Convert SPSS from wide to long
spssDataMeanLong <- gather(spssMeansData, ExpType, Prop, Single:Super_par, factor_key=TRUE)
spssDataSDLong <- gather(spssStdDevData, ExpType, Prop, Single:Super_par, factor_key=TRUE)
spssDataMeanLong <- spssDataMeanLong[c("ExpType", "Proportion", "Prop")]
spssDataSDLong <- spssDataSDLong[c("ExpType", "StdDev", "Prop")]
names(spssDataMeanLong)[names(spssDataMeanLong) == 'Proportion'] <- 'GeneralizationLevel'
names(spssDataSDLong)[names(spssDataSDLong) == 'StdDev'] <- 'GeneralizationLevel'
names(spssDataSDLong)[names(spssDataSDLong) == 'Prop'] <- 'SD'
# Merge SPSS means and SD data
spssDataMeanLong$SD <- spssDataSDLong$SD
spssDataMeanLong$source <- 'Human'
# Convert NGM output from wide to long
ngmOutputMeanLong <- gather(ngmOutputMean, ExpType, Prop, Single:Super_par, factor_key=TRUE)
ngmOutputSDLong <- gather(ngmOutputSD, ExpType, Prop, Single:Super_par, factor_key=TRUE)
ngmOutputMeanLong <- ngmOutputMeanLong[c("ExpType", "Proportion", "Prop")]
ngmOutputSDLong <- ngmOutputSDLong[c("ExpType", "Proportion", "Prop")]
names(ngmOutputMeanLong)[names(ngmOutputMeanLong) == 'Proportion'] <- 'GeneralizationLevel'
names(ngmOutputSDLong)[names(ngmOutputSDLong) == 'Proportion'] <- 'GeneralizationLevel'
names(ngmOutputSDLong)[names(ngmOutputSDLong) == 'Prop'] <- 'SD'
# Merge NGM means and SD data
ngmOutputMeanLong$SD <- ngmOutputSDLong$SD
ngmOutputMeanLong$source <- 'NGM'
# Cat NGM and human data
combinedData <- rbind(spssDataMeanLong, ngmOutputMeanLong)
combinedData <- combinedData %>%
mutate(
GeneralizationLevel = fct_recode(GeneralizationLevel, Subordinate = "0_SUBORDINATE"),
GeneralizationLevel = fct_recode(GeneralizationLevel, Basic = "1_BASIC"),
GeneralizationLevel = fct_recode(GeneralizationLevel, Superordinate = "2_SUPERORDINATE"))
combinedData$source <- as.character(combinedData$source)
# Add columns for upper and lower error bars
combinedData$lowerError <- combinedData$Prop - combinedData$SD
combinedData$upperError <- combinedData$Prop + combinedData$SD
combinedData$lowerError[combinedData$lowerError < 0.0] <- 0.0
combinedData$upperError[combinedData$upperError > 1.0] <- 1.0
# Filter to only just those to plot
singleData <- combinedData %>% filter((ExpType == "Single"))
subSeqData <- combinedData %>% filter((ExpType == "Sub_seq"))
basicSeqData <- combinedData %>% filter((ExpType == "Basic_seq"))
superSeqData <- combinedData %>% filter((ExpType == "Super_seq"))
subParData <- combinedData %>% filter((ExpType == "Sub_par"))
basicParData <- combinedData %>% filter((ExpType == "Basic_par"))
superParData <- combinedData %>% filter((ExpType == "Super_par"))
#########################
#########################
## Call plotting function
#########################
#########################
outputname = paste(outputDir,'singleDataPlot.png',sep="")
plottitle = 'Single Item Training'
makePlot(singleData,outputname,plottitle)
outputname = paste(outputDir,'subSeqDataPlot.png',sep="")
plottitle = 'Sequential Subortinate Training'
makePlot(subSeqData,outputname,plottitle)
outputname = paste(outputDir,'basicSeqDataPlot.png',sep="")
plottitle = 'Sequential Basic Training'
makePlot(basicSeqData,outputname,plottitle)
outputname = paste(outputDir,'superSeqDataPlot.png',sep="")
plottitle = 'Sequential Superordinate Training'
makePlot(superSeqData,outputname,plottitle)
outputname = paste(outputDir,'subParDataPlot.png',sep="")
plottitle = 'Simultaneous Subortinate Training'
makePlot(subParData,outputname,plottitle)
outputname = paste(outputDir,'basicParDataPlot.png',sep="")
plottitle = 'Simultaneous Basic Training'
makePlot(basicParData,outputname,plottitle)
outputname = paste(outputDir,'superParDataPlot.png',sep="")
plottitle = 'Simultaneous Superordinate Training'
makePlot(superParData,outputname,plottitle)
## Finished