3

I am trying to increase the space between box plots in a diagram generated by ggplot2. I found an answer to how to do it for barplots which I was not able to adapt but which at least makes me more hopeful. I have the following code:

library('ggplot2')
FOO <- runif(30, min=0, max=10);
BAR <- rep(c("a", "b", "c"), 10)

df <- data.frame(FOO, BAR);
ggplot(df, aes(x = BAR, y = FOO)) + geom_boxplot(outlier.shape = NA, fill = "grey80",alpha = 0.3) + geom_point(position = position_jitter(w = 0.5, h = 0)) + theme_bw()

enter image description here

It is really difficult to see which dataset the dots belong to. I realise that I can change the w in the position_jitter but that also increases the risk of overlap. I would like to also be able to increase the space between the plots. How can this be done?

Community
  • 1
  • 1
jonalv
  • 5,706
  • 9
  • 45
  • 64

1 Answers1

1

I don't understand this plot and don't think it will become better, even if you increase the space between the groups:

ggplot(df, aes(x = BAR, y = FOO)) + 
  geom_boxplot(outlier.shape = NA, fill = "grey80",alpha = 0.3, width=0.5) + 
  geom_point(position = position_jitter(w = 0.15, h = 0)) + 
  theme_bw()

enter image description here

Roland
  • 127,288
  • 10
  • 191
  • 288
  • 2
    That's an interesting statement. Would you care to extend on what is wrong with wanting to, for a small dataset, show both box plots as well as the actual points? – jonalv Nov 08 '13 at 11:00
  • If you add jitter like this, my brain automatically assumes that it's dealing with a scatter plot. Without knowing the code or reading a descriptive figure caption, I wouldn't know how to interpret the distribution of the points on the x-axis. Why do you need to add jitter? – Roland Nov 08 '13 at 12:18
  • If I don't, then some points will land on top of each other. (At least for my data) – jonalv Nov 08 '13 at 12:20