-1

I am using R to analyse some ecological data, and when I try to create a boxplot two different boxes appear for one of my variables.

Here is my code:

plot(Ratio.gap.per ~ Circadian, data=circ)

which should produce a boxplot with a box for each of my x axis factors, but I always get two different bars for my category N (for 'nocturnal'). Boxplot shown here:

Does anyone know how to correct this?

Anonymous coward
  • 2,061
  • 1
  • 16
  • 29
  • 2
    Welcome to SO! Please read [this post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a reproducible example. – emilliman5 Oct 25 '18 at 16:17
  • 1
    Are you sure those two groups are identical? Rather than, say, `"N"` and `"N "`? – camille Oct 25 '18 at 17:47

1 Answers1

0

It looks like some of your data is coded as "N " (with a space) rather than "N".

Try

circ$Circadian[circ$Circadian=="N "] <- "N"

and then if needed (i.e. if circ$Circadian is a factor),

circ$Circadian <- as.factor(as.character(circ$Circadian))

to get rid of the extra factor level.

Matt Tyers
  • 2,125
  • 1
  • 14
  • 23