rmeanstandard-deviationlinegraphstdev

How to set zero as the mean value when plotting a line graph in R of distance travelled per day


I'm trying to plot a line graph in R displaying distance travelled per day by an individual, with days on the x axis and distance travelled (per day) on the y axis.

I want to set the value of zero so that it is equal to the mean distance travelled. This is so that I can assess when movements were more than 2 standard deviations from the mean distance. Is there a simple way to do this in R?

My data format:

Day Distance
1    5.09902
2    0.00000
3    0.00000
4    5.09902
5    0.00000
6    0.00000 

Each row represents distance travelled per day from one location to the following location.

Solution followed and data plotted:

ig1$stdDist <- (ig1$Distance - mean(ig1$Distance))/sd(ig1$Distance)

plot(ig1$stdDist)

plot(ig1$stdDist, type = "o",col = "red", xlab = "Days", ylab = "Stdev", 
     main = "IG001")

enter image description here


Solution

  • Since you ultimately seem to be interested in looking at how many standard deviations a distance is from the mean, you may want to try standardizing your distance measurements. You could try something like

    data$stdDist <- (data$Dist - mean(data$Dist))/sd(data$Dist)
    

    data$stdDist tells you how many standard deviations above or below the mean each of your original distances was. (Note--the code above assumes you have no missing values.)