+2 votes
in Programming Languages by (21.4k points)

I am using ggplot2 to generate errorbar plots. My code gives a warning message: "position_dodge requires non-overlapping x intervals" and error bars are scattered on the plot.

Here is the data frame that I am using for the plot.

true_fracs <- c(0.01, 0.05, 0.10, 0.20, 0.30, 0.40)

df <- data.frame(

  truefracs = c(true_fracs, true_fracs, true_fracs),

  mean_est_fracs = c(mean_vec_pl, mean_vec_dp, mean_vec_cl),


p<- ggplot(df, aes(x=truefracs, y=mean_est_fracs, fill=Algorithms))

In the ggplot, I am using "truefracs" as x-axis values and "mean_est_fracs" as y-axis values. The length of each of the mean_vec is 6. So, there is nothing wrong with the dataframe. How can I fix it?

1 Answer

+1 vote
by (51.1k points)

I think you are using continuous values for both the x and y-axis. That's why the ggplot module is throwing the warning message. If you change the values of true_fracs from numbers to characters, it should fix the error.

Make the following change in your code, and it should work.


true_fracs <- c(0.01, 0.05, 0.10, 0.20, 0.30, 0.40)


true_fracs <- c("0.01", "0.05", "0.10", "0.20", "0.30", "0.40")