### Jittered dot plots with error bars
### First plot is for one group, so X = constant (defined in the body of the code)
### Second plot is for two groups, so X = grouping variable

#In geom_jitter, w = how far from the center points may spread horizontally, and h = denotes the same vertically
#In stat_summary for the mean, size and color refer to the dot representing the mean
#In stat_summary for the confidence interval, the raw interval is the standard error, so multiplying by 1.96
#converts it to a 95% confidence interval; width denotes the actual width of the confidence interval
# the three final theme elements in the first plot fade away the X axis, which is not needed for that example

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
#More modern venues want to see the spread of points. 
#We do this via a jittered dot plot with error bars.
Wk06$constant=1
library(ggplot2)
p <- ggplot(Wk06, aes(y=height, x=constant))+
# geom_point() +
geom_jitter(position=position_jitter(w=0.15, h=1)) +
stat_summary(fun.y="mean", geom="point", size=2.5, color="red") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar",
fun.args = list(mult = 1.96), color="red", width=.4) +
labs(y = "Height", x = "Sample values") +
theme_bw() +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
## Warning: `fun.y` is deprecated. Use `fun` instead.
p

p2 <- ggplot(Wk06, aes(y=height, x=handed))+ 
# geom_point() +
geom_jitter(position=position_jitter(w=0.15, h=1)) +
stat_summary(fun.y="mean", geom="point", size=2.5, color="red") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar",
fun.args = list(mult = 1.96), color="red", width=.4) +
labs(y = "Height", x = "Handedness") +
theme_bw()
## Warning: `fun.y` is deprecated. Use `fun` instead.
p2