Confidence Interval Plots Using Tidy
install.packages("tidyr", dependencies = TRUE) library(ggplot2) library(tidyr) library(dplyr) theme_set(theme_bw()) Group <- sample(LETTERS[1:3], 1000, replace = TRUE) Group2 <- sample(LETTERS[24:26], 1000, replace = TRUE) catDV <- sample(1:5, 1000, replace = TRUE) catDV2 <- sample(1:5, 1000, replace = TRUE) data <- data.frame(Group, Group2, catDV, catDV2) Tidy <- data %>% group_by(Group, Group2) %>% summarise(Mean = mean(catDV, na.rm=TRUE) , stdDev = sd(catDV, na.rm=TRUE), NN = length(catDV)) Tidy # A tibble: 9 x 5 # Groups: Group [?] Group Group2 Mean stdDev NN <fctr> <fctr> <dbl> <dbl> <int> 1 A X 3.117021 1.382349 94 2 A Y 3.112150 1.268836 107 3 A Z 3.099099 1.458237 111 4 B X 3.185185 1.399281 135 5 B Y 3.174312 1.489743 109 6 B Z 2.845528 1.498811 123 7 C X 2.934066 1.533349 91 8 C Y 2.761905 1.431270 105 9 C Z 2.936000 1.401290 125 Tidy$SE <- Tidy$stdDev/sqrt(Tidy$NN) Tidy$Low <- Tidy$Mean - 1.96 * Tidy$SE Tidy$High <- Tidy$Mean + 1.96 * Tidy$SE qplot(data = Tidy, x = Group, y = Mean, ymin = Low, ymax = High, geom= "pointrange", colour = Group2 , facets = ~Group2)