How to create a graph of means and standard deviation in a data set that includes missing values (NAs)

2

Hello!

I work with bioacoustics and am trying to create a graph of means by species using the lineplot.CI function of the sciplot package, but I can not get the R to ignore the missing values (NA). When I graph the durations of notes, everything is fine because the DeltaTime variable does not include NAs:

library(sciplot)
# Note duration
lineplot.CI(dados$especie, dados$DeltaTime, las=1, type="p",
        xlab="Espécie", ylab="Duração nota", main="Duração nota",
        ci.fun= function(x) c(mean(x)-sd(x), mean(x)+sd(x)))

WhenItrytousethesamefunctionforthePeakFreqvariable,ontheotherhand,thestandarddeviationbarsonlyappearforthespeciesthatdoesnothaveanyNA:

lineplot.CI(dados$especie,dados$PeakFreq,las=1,type="p",
        xlab="Espécie", ylab="Frequência dominante", main="Frequência 
        dominante",
        ci.fun= function(x) c(mean(x)-sd(x), mean(x)+sd(x)))  

I have tried to change the function in several ways and I searched a lot on the internet, but I did not succeed. Any ideas how to fix this?

obs: The function has no problem ignoring NAs when we consider only the default error

    
asked by anonymous 08.06.2017 / 17:30

1 answer

1

You have to explicitly ask for the functions mean() and sd() to ignore the NA , passing the argument na.rm = TRUE :

lineplot.CI(dados$especie, dados$DeltaTime, las=1, type="p",
            xlab="Espécie", ylab="Duração nota", main="Duração nota",
            ci.fun= function(x) c(mean(x, na.rm = TRUE)-sd(x, na.rm = TRUE), 
                                  mean(x, na.rm = TRUE)+sd(x, na.rm = TRUE)))
    
10.06.2017 / 09:47