0

I have a data frame like this

head(data)

 n   OESST      wsB
 4  0.52924690   4
 8  0.04488144   6
 6  0.29909668   6
 0  1.42228888   6
 2  1.92228888   4
 4  1.85659560   6

and I am doing a box plot of OESST as a function of wsB for the different n values

ggplot(na.omit(data), aes(x=factor(wsB), y=OESST, colour = factor(n))) + geom_boxplot(outlier.size=0,fill = "white",position="dodge",size=0.3,alpha=0.3) + stat_summary(fun.y=median, geom="line", aes(group=factor(n), colour = factor(n)),size=1)

What I would like to do is to remove from the plot the unique n-wsB combinations (which are visualized only as a line but don't have actually a box).

Any help?

Thanks

user3036416
  • 1,205
  • 2
  • 15
  • 28
  • So are there any lines from your sample data that would be plotted? If not, can you please make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) such that we can try plotting the data to see what happens. – MrFlick Oct 30 '14 at 19:57

1 Answers1

1

I think the best approach is just filter your data first. Using dplyr

library(dplyr)
data %>%
  group_by(n, wsB) %>%
  mutate(n.wsB.count = n()) %>%
  filter(n.wsB.count > 1) %>%
  na.omit() %>%
ggplot(aes(x=factor(wsB), y=OESST, colour = factor(n))) +
  geom_boxplot(outlier.size=0,fill = "white", position="dodge", size=0.3, alpha=0.3) + 
  stat_summary(fun.y=median, geom="line", aes(group=factor(n)), size=1)

Not tested as (@MrFlick points out) the provided data isn't reproducible for the problem. I also took out the redundant colour aesthetic in the stat_summary.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294