Created
June 30, 2017 01:04
-
-
Save derekpowell/4a8dea27d27990973898f05972ebd7a1 to your computer and use it in GitHub Desktop.
R: standard error functions for use in ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# standard error function | |
stderr <- function(x) { | |
sqrt(var(x[!is.na(x)]) / length(x[!is.na(x)])) | |
} | |
# Then create a wrapper to *stderr* to make it compatible with *stat_summary* | |
my.stderr <- function(x) { | |
meany <- mean(x) | |
ymin <- mean(x) - stderr(x) | |
ymax <- mean(x) + stderr(x) | |
# assemble the named output | |
out <- c(y = meany, ymin = ymin, ymax = ymax) | |
return(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment