Skip to content

Instantly share code, notes, and snippets.

@kohske
Last active December 11, 2015 09:18
Show Gist options
  • Select an option

  • Save kohske/4578531 to your computer and use it in GitHub Desktop.

Select an option

Save kohske/4578531 to your computer and use it in GitHub Desktop.
Temporary patch for stat_summary with geom_line
library(ggplot2)
library(proto)
StatSummary <- proto(ggplot2:::Stat, {
objname <- "summary"
default_geom <- function(.) GeomPointrange
required_aes <- c("x", "y")
calculate_groups <- function(., data, scales, fun.data = NULL, fun.y = NULL, fun.ymax = NULL, fun.ymin = NULL, na.rm = FALSE, ...) {
data <- remove_missing(data, na.rm, c("x", "y"), name = "stat_summary")
if (!missing(fun.data)) {
fun.data <- match.fun(fun.data)
fun <- function(df, ...) {
fun.data(df$y, ...)
}
} else {
fs <- compact(list(ymin = fun.ymin, y = fun.y, ymax = fun.ymax))
fun <- function(df, ...) {
res <- llply(fs, function(f) do.call(f, list(df$y, ...)))
names(res) <- names(fs)
as.data.frame(res)
}
}
summarise_by_x(data, fun, ...)
}
})
assignInNamespace("StatSummary", StatSummary, pos = "package:ggplot2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment