Data Cleaning
#longData <- read_csv('cameron-longData1.xlsx', na=".",col_names=TRUE)
### Create Names
names(data) <- paste(c("Study 1", "Study 2", "Study 3"))
### Create table of samples sizes and remove row of sample sizes from data frame
sampleSize <- data[1,]
sampleSize <- data.frame(n = unlist(transpose(as.vector(sampleSize))))
sampleSize$whichEvent <- row.names(sampleSize)
## Remove row
data <- data[-1,]
### Create columns with labels for correlations
data$trait <- rep(c("O", "C", "E", "A", "N"), each = 3)
data$Contexts <- rep(c("OFF/NC",
"SM/NC",
"SM/OFF"), times=5)
### Reshape data for plotting (tidyr)
longData <- data %>%
pivot_longer(col = starts_with(c("Study 1", "Study 2", "Study 3")),
names_to = "whichEvent", values_to = "correlation") %>%
separate(whichEvent, into = c("Study"), sep="_", remove = FALSE)
## Add Sample Size
longData <- left_join(longData, sampleSize, by = "whichEvent")
## Calculate confidence intervals
longData <- longData %>%
mutate(z = .5 * log((1 + correlation)/(1 - correlation)), ## Z
se = 1/sqrt(n - 3), ## SE
upperz = z + qnorm(.025, lower.tail=FALSE)*se, ## upper CI for Z
lowerz = z - qnorm(.025, lower.tail=FALSE)*se, ## lower CI for Z
upperr = (exp(2*upperz) - 1) / (exp(2*upperz) + 1), ## upper CI for r
lowerr = (exp(2*lowerz) - 1) / (exp(2*lowerz) + 1)) ## lower CI for r
longData$trait <- factor(longData$trait, levels=c("O", "C", "E", "A", "N"))
Plot 1
plot1 <-
ggplot(longData,
aes(x = Contexts, y = correlation, ymin = lowerr,
ymax=upperr, color=trait, shape=trait)) +
scale_shape_manual(values=c(4, 15, 16, 17, 18))+
scale_color_grey()+
geom_pointrange(position = position_dodge(width=.5)) +
geom_hline(yintercept=0, lty=2) +
scale_y_continuous(limits = c(.00, 1.00)) +
xlab("Contexts") + ylab("r (95%CI)") +
ggtitle("Associations between contexts and personality traits") +
facet_wrap(~Study, nrow=3) +
theme_bw()+
theme(axis.text.x = element_text(size = 10, angle=0))
print(plot1)
Plot 2
plot2 <-
ggplot(longData,
aes(x = Contexts, y = correlation, ymin = lowerr,
ymax=upperr, color=trait, shape=trait)) +
scale_shape_manual(values=c(4, 15, 16, 17, 18))+
scale_color_grey()+
geom_pointrange(position = position_dodge(width=.5)) +
geom_hline(yintercept=0, lty=2) +
scale_y_continuous(limits = c(.00, 1.00)) +
xlab("Contexts") + ylab("r (95%CI)") +
ggtitle("Associations between contexts and personality traits") +
theme_bw()+
theme(axis.text.x = element_text(size = 10, angle=0))
print(plot2)