Function

コメント・参照等

FUN = f_ggplot_smooth.r
function (g, tidydata, col_x = 1, col_y = 2, col_key = 3, size = 1, methods = "loess", col = "red", se = T, show_legend = F, all_key = T) 
{
    tidydata <- tidydata[, c(col_x, col_y, col_key)]
    colnames(tidydata) <- c("x", "y", "key")
    f_smooth_method <- function(formula, data, ...) {
        meth <- eval(parse(text = methods[unique(data$PANEL)]))
        x <- match.call()
        x[[1]] <- meth
        eval.parent(x)
    }
    if (all_key) {
        key_n <- length(unique(tidydata$key))
        methods <- head(rep(methods, ceiling(key_n/length(methods))), key_n)
    }
    print(methods)
    g <- g + geom_smooth(data = tidydata, mapping = aes(x = x, y = y), se = se, size = size, method = f_smooth_method, col = col, show.legend = show_legend)
    return(g)
}