First – full disclosure: I am a coding newbie. I have googled this to death, and if there are posts explaining how to do this, then I either didn’t find them or (more likely) don’t understand them!! I tried to post the images but evidently my reputation isn't ready for that...
I am trying to produce some box plots and want the outlier colors to match the fill color of the box, and I want to be able to choose those colors. So here is my original code:
PIPO.box = ggplot(data = rim.sbs, aes(x=as.factor(Year), y=PIPO2))+
geom_boxplot(aes(fill=Mulched)) +
scale_fill_manual(name = " ", values = c("grey", "white")) + labs(x = "", y = "Ponderosa pine seedlings/ha\n") + theme_bw(base_size = 24) +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(size = 18))
PIPO.box
With much googling I figured out how to make the box and outlier colors consistent within treatment. Its mostly what I want, but not in pastel colors! I also want one the treatments to have a filled box, as in the graph created above. So I kind of want a combination of the two.
PIPO.box = ggplot(data = rim.sbs, aes(x=as.factor(Year), y=PIPO2))+
geom_boxplot(aes(colour = Mulched)) +
scale_fill_manual(name = " ", values = c("grey", "white")) + labs(x = " ", y = "Ponderosa pine seedlings/ha\n") +
theme_bw(base_size = 24) + theme(panel.border = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(size = 18))
PIPO.box
I tried scale_fill_manual which lets me choose the colors but then I don’t get the outliers to match. I did find a crafty workaround on one of these help sites, creating a dataset with the outliers in it and then re-adding them in my chosen colors with geom_points, but that code is written for one factor and I can’t figure out how to shift the points to split across both factors, see below. And again it’s those pesky pastels!
library(plyr)
plot_Data <- ddply(rim.sbs, .(Year), mutate, Q1=quantile(PIPO2, 1/4), Q3=quantile(PIPO2, 3/4), IQR=Q3-Q1, upper.limit=Q3+1.5*IQR, lower.limit=Q1-1.5*IQR)
PIPO.box = ggplot(data = rim.sbs, aes(x=as.factor(Year), y=PIPO2))+
geom_boxplot(aes(fill=Mulched)) +
scale_fill_manual(name = " ", values = c("grey", "white")) + labs(x = " ", y = "Ponderosa pine seedlings/ha\n") + theme_bw(base_size = 24) +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(size = 18))
PIPO.box + geom_point(data=plot_Data[plot_Data$PIPO2 > plot_Data$upper.limit | plot_Data$PIPO2 < plot_Data$lower.limit,], aes(x=factor(Year), y=PIPO2, col=factor(Mulched)))
Any help in creating box plots with fill and outlier colors by factor, and of my own choosing, would be greatly appreciated!!