uberpro
uberpro

Reputation:

Geom_points not dodging when geom_errorbars are

I can't figure out how to get these geom_points to properly dodge! I've searched many, MANY how-to's and questions on different stackexchange pages, but none of them fix the problem.

analyze_weighted <- data.frame(
    mus = c(clean_mu,b_mu,d_mu,g_mu,bd_mu,bg_mu,dg_mu,bdg_mu,m_mu),
    sds = c(clean_sigma,b_sigma,d_sigma,g_sigma,bd_sigma,bg_sigma,dg_sigma,bdg_sigma,m_sigma),
    SNR =c("No shifts","1 shift","1 shift","1 shift","2 shifts","2 shifts","2 shifts","3 shifts","4 shifts"),
)

And then I try to plot it:

ggplot(analyze_weighted, aes(x=SNR,y=mus,color=SNR,group=mus)) + 
  geom_point(position="dodge",na.rm=TRUE) + 
  geom_errorbar(position="dodge",aes(ymax=mus+sds/2,ymin=mus-sds/2,), width=0.25) 

And it manages to dodge the error bars but not the points! I'm going crazy here, what do I do?

Here's what it looks like now--I want the points to be slightly dodged!

The points refuse to dodge, no matter what I do!

Upvotes: 1

Views: 308

Answers (1)

PavoDive
PavoDive

Reputation: 6496

geom_point requires that you explicitly provide the width you desire the points to dodge.

This should work:

ggplot(analyze_weighted, aes(x=SNR,y=mus,color=SNR,group=mus)) + 
  geom_point(position=position_dodge(width=0.2),na.rm=TRUE) + 
  geom_errorbar(position=position_dodge(width=0.2),aes(ymax=mus+sds/2,ymin=mus-sds/2),width=0.25) 

Please notice that your example wasn't a fully reproducible one, as no values of the variables used to construct mus and sds are available.

Upvotes: 1

Related Questions