1

I have made a box plot with geometric means with the following code

bp.vals <- function(x, probs=c(0.05, 0.25, 0.75, .95)) {
    r <- quantile(x, probs=probs, na.rm=TRUE)
    r = c(r[1:2], exp(mean(log(x))), r[3:4])
    names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
    r
}
ggplot(data_7m, aes(x=factor(BCG), y= IPVtype1_7m, fill=Group, width=0.4)) + 
     scale_fill_manual(values = c("dark grey", "light grey")) +
     stat_summary(fun.data=bp.vals, geom="boxplot", show.legend=F) + 
     labs(x="", y="GMC(IU/mL)")

I would like to move the boxes closer together, but cannot get it to work. I have tried space, position and par()function.

Does anybody know how to do this?
Box plot geometric mean

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Petra
  • 45
  • 1
  • 1
  • 6
  • What do you mean by "move the boxes closer together"? Make the boxes wider? Decrease the width of the whole plot? Leave the plot exactly as it is but move the breaks of the x-axis closer to the middle? – Roland Jun 07 '18 at 13:48
  • You should probably change the `width` parameter. – Axeman Jun 07 '18 at 14:19
  • Sorry, for not asking my question clearer. I do not want to change the width of the boxes, but I want to decrease the width of the whole plot and especially the space between the two boxes. – Petra Jun 07 '18 at 17:11
  • Just change the size of the graphics window or even better use ggsave to export the plot with specified dimensions. – Roland Jun 07 '18 at 17:35
  • [This](https://stackoverflow.com/questions/49041183/reduce-space-between-groups-of-bars-in-ggplot2) and [this](https://stackoverflow.com/questions/25887066/remove-space-between-bars-ggplot2) seem related – aosmith Jun 07 '18 at 18:40

1 Answers1

0

In lieu of a reproducible example, increase the width parameter. The width parameter is commonly used with geom_bar (e.g. geom_bar(stat="identity", width=0.9) and geom_boxplot (geom_boxplot(width=0.9)).

ggplot(data_7m, aes(x=factor(BCG), y=IPVtype1_7m, fill=Group) + 
     geom_bar(stat="identity", width=0.9) +
     scale_fill_manual(values = c("dark grey", "light grey")) +
     labs(x="", y="GMC(IU/mL)"
Sarah Grogan
  • 117
  • 1
  • 9