0

I don't why my graph looks this way or how to fix it. I've adapted the code from a two-groups graph to 3 groups. How do I remove the NA from the graph and center the error bars and dots?

a = ggplot(tmp.df, aes(Goal, Score, fill=group)) + 
geom_boxplot(stat = "boxplot",position = "dodge2",outlier.shape = NA, coef = 0, na.rm = TRUE) +
geom_errorbar(data = x, aes(y=fit, ymin=lower, ymax=upper), width=0.3, position = position_dodge(0.4)) + 
geom_point(data = x, aes(y=fit), position = position_dodge(0.4)) +
scale_fill_manual(name = "group", labels = c("General", "Religious", "Minorities"),
values = c("firebrick4", "deepskyblue4","hotpink2")) + coord_cartesian(ylim = c(0, 4)) +
ylab("Goal's Importance") +
theme_bw(base_size=13) +
theme(axis.text.x = element_text(angle = 345),
panel.grid.major.x = element_blank()) 

enter image description here

Also, why do I keep getting this error message?

> ggsave(a, filename = "4.png", width = 180, height = 160, units = "mm",  bg = "transparent") + 
#scale_fill_discrete( labels = c("General", "Religious", "Minorities")) + 
ggtitle("Goals' Importance by Group")

Error in ggsave(a, filename = "4.png", width = 180, height = 160, units = "mm", : non-numeric argument to binary operator

  • You do not need to specify `position` for your error bars. You have provided their position on the x-axis in your `aes` and on the y-axis with `y`, `ymin`, and `ymax`. That argument is adjusting the error bars. In `ggsave`, the default is to save the last plot so you shouldn't need to supply `a` here. If you do then `ggsave(plot=a,...)`. – LMc Feb 03 '21 at 18:12
  • If this does not work, please provide your data in your question by pasting the output from `dput(tmp.df)`. – LMc Feb 03 '21 at 18:14
  • See [this guide](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to provide a reproducible example in your questions. Welcome to SO! – BroVic Feb 03 '21 at 18:46

0 Answers0