Using ggplot2, I want to geom_jitterdodge a swarm of points with overlayed dodged boxplots. The trick is that I want the boxplots to be black, not colored like the points. The point plot looks like this:
It's easy enough to get boxplots in place:
The code for that looks like this:
D_cohort1 %>%
filter(!is.na(pssa_ela_code)) %>%
ggplot(aes(x=timepoint,
y=dibels_lnf,
color=pssa_ela_code)) +
geom_point(alpha=1/6, size=2, width=1/3, height=0,
position=position_jitterdodge()) +
geom_boxplot(fill=NA, outlier.shape=NA,
position=position_dodge2(padding=.3)) +
facet_grid(rows=vars(school_type)) +
guides(colour = guide_legend(override.aes = list(alpha=1))) +
labs(title="Figure A.1: DIBELS LNF Scores at each Timepoint") +
theme_cowplot() +
theme(plot.background=element_rect(fill="aliceblue"),
panel.border=element_rect(color="black", fill=NA),
legend.position = c(.85,.87),
legend.text = element_text(size = rel(.7)))
For visibilities sake, I want the boxplot lines to be black, but I can't quite figure out how to get there. Closest I've come is this (same as before but for the call to geom_boxplot():
D_cohort1 %>%
filter(!is.na(pssa_ela_code)) %>%
ggplot(aes(x=timepoint,
y=dibels_lnf,
color=pssa_ela_code)) +
geom_point(alpha=1/6, size=2, width=1/3, height=0,
position=position_jitterdodge()) +
geom_boxplot(aes(color=NULL, group=fct_cross(timepoint, pssa_ela_code)),
fill=NA, outlier.shape=NA,
position=position_dodge2(padding=.3)) +
facet_grid(rows=vars(school_type)) +
guides(colour = guide_legend(override.aes = list(alpha=1))) +
labs(title="Figure A.1: DIBELS LNF Scores at each Timepoint") +
theme_cowplot() +
theme(plot.background=element_rect(fill="aliceblue"),
panel.border=element_rect(color="black", fill=NA),
legend.position = c(.85,.87),
legend.text = element_text(size = rel(.7)))
That gets the color effect I want, but positions the boxplots incorrectly. Shown here:
How can I achieve the effect I want: correctly positioned, black boxplots over colored points?