1

I have data over 15 consecutive months, but there are no observations for month 12.

I have "month" coded in the data.frame as an integer from 1 to 15. There are no occurrences of 12.

boxplot (data$y ~ data$month) seems to convert month to a factor, with 14 levels, so I don't see a gap where month 12 data would be, if there were any.

How can I get boxplot to leave a gap at 12? I'd like to overlay a regression line, but it won't be right without the gap.

Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48
Gerry
  • 1,303
  • 1
  • 10
  • 16

1 Answers1

4

You are right that boxplot() converts your months to a factor.

Tell R explicitly that 12 would be a valid factor level, and you are good to go:

data <- data.frame(y=rnorm(200),month=sample(c(1:11,13:15),200,replace=TRUE))
with(data,boxplot(y~factor(month,levels=1:15)))

boxplots

Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48