0

I am using facet wrap in ggplot to create boxplots. I am using the fill commend to further break up the data by color. Using other stackoverflow help, I've been able to add points on top of those boxplots. I am now trying to center those dots on each boxplot. As you can see in the screenshot, the dots are actually centered around the variable "salt" on the x axis, instead of being centered on their respective boxplot. Do you have any suggestions on how to deal with this?

Thanks so much for your help!

facetted box and whisker plot with points

My code:

I<-ggplot(IntTrt72, aes(x=salt, y=rel_diff, fill = stage))+
  geom_boxplot(outlier.size = 0.1) + theme_classic() +
  theme(strip.background = element_blank(), strip.text.x = element_blank(), legend.position = "none")+
  geom_dotplot(binaxis = 'y', stackdir = 'center', binwidth = .05,
               color = NA,position = position_dodge())

I<-I+scale_fill_manual(values=c("#5445b1", "#749dae", "#f3c483"))+ theme_classic()+
  theme(strip.background = element_blank(), strip.text.x = element_blank(), legend.position = "none")
I<- I+facet_wrap(treatmenthours~temp)
I<- I + geom_hline(yintercept=0, linetype="dashed", color = "grey60")
I<- I + scale_y_continuous( breaks=c(-1.0, -0.75, -0.5, -0.25, 0, 0.25), limits=c(-1.0, 0.3))
I

FYI, I am an R beginner.

r2evans
  • 141,215
  • 6
  • 77
  • 149
J. B.
  • 1
  • 1
    It kind of looks like the dotplots are being "dodged" more than the boxplots. Maybe try to set the dodging width inside `position_dodge()` in the dotplot layer, like `position_dodge(width = .75)`? That being said, it'll be much easier for folks to help you if you provide a small example of your dataset so folks can run your code. :) See ideas on how to do that [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – aosmith May 24 '21 at 14:27
  • That fixed it! Thank you so much for your help. For other's reference, that code now looks like this: I<-ggplot(IntTrt72, aes(x=salt, y=rel_diff, fill = stage))+ geom_boxplot(outlier.size = 0.1) + theme_classic() + theme(strip.background = element_blank(), strip.text.x = element_blank(), legend.position = "none")+ geom_dotplot(binaxis = 'y', stackdir = 'center', binwidth = .05, color = NA, position = position_dodge(width = .75)) Thank you, R2evans! – J. B. May 24 '21 at 15:10

0 Answers0