'ggplot2 geom_point position= "dodges" doesn't match the error bar dodge

Im trying to figure out the best way to plot changes in water potential through summer comparing two factors, soil cover treatments and irrigation. I reached a fair result but im having troubles that the geom_points doesn't follow the position_dodge as the error bar.

Example:Best Try

Stats <- summarySE(Maiten, measurevar= "Potencial", groupvars=c("Fecha","Riego","Tratamiento"),na.rm=TRUE)
ggplot(Stats, aes(x=Fecha, y=Potencial, group=Riego, colour=Riego,shape=Tratamiento))+
geom_errorbar(aes(x=Fecha, ymax=Potencial+se, ymin=Potencial-se),position="dodge")+
geom_point(position="dodge",size=3)+theme_classic()

Though this code give me this warning "Warning message: Width not defined. Set with position_dodge(width = ?) " if i alter the width neither the error bars or points dodge.

Example: modifiying position_dodge(width =0.9)

Any help or guidance would be appreciated!



Solution 1:[1]

It's difficult to know what could be happening without a sample of data to work with, but to demonstrate, position = position_dodge(width = 0.9) in each geom call should put the dodged parts in the same places:

library(ggplot2)

ggplot(ChickWeight, aes(Time, weight, colour = Diet)) +
  stat_summary(geom = "errorbar", position = position_dodge(width = 0.9)) +
  stat_summary(geom = "point", position = position_dodge(width = 0.9)) 
#> No summary function supplied, defaulting to `mean_se()`
#> No summary function supplied, defaulting to `mean_se()`

(also to demonstrate here that stat_summary will do most of your mean/se plotting within a function call, grouping accordingly)

Created on 2022-05-12 by the reprex package (v2.0.1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy Baxter