0

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!

Axeman
  • 32,068
  • 8
  • 81
  • 94
ocrovo
  • 1
  • 1
    Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Axeman May 12 '22 at 21:39

1 Answers1

0

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)

Andy Baxter
  • 5,833
  • 1
  • 8
  • 22
  • 1
    Thanks! i actually replace my factors and data from the code you sent and continue to have the same problem, then i replace the "date" format from my x-axxis and the dodge work out. – ocrovo May 12 '22 at 22:29
  • Ah that's interesting! It might have been that `position = position_dodge(width = 0.9)` in your first plotting of the graph was separating your points over 0.9 *days* in the date formatted axis. You could try `width = 10` or similar on a date formatted axis and see if that achieves anything too! – Andy Baxter May 14 '22 at 11:33