Here is how to calculate the median median line here . R implementation is
median_median_line <- function(x, y, data) { if(!missing(data)) { x <- eval(substitute(x), data) y <- eval(substitute(y), data) } stopifnot(length(x) == length(y))
To test this, here is the second example from this page:
dfr <- data.frame( time = c(.16, .24, .25, .30, .30, .32, .36, .36, .50, .50, .57, .61, .61, .68, .72, .72, .83, .88, .89), distance = c(12.1, 29.8, 32.7, 42.8, 44.2, 55.8, 63.5, 65.1, 124.6, 129.7, 150.2, 182.2, 189.4, 220.4, 250.4, 261.0, 334.5, 375.5, 399.1)) median_median_line(time, distance, dfr)
Pay attention to a somewhat strange way of defining groups. The instructions are quite complicated in how you determine the size of the groups, so the more obvious cut(x, quantile(x, seq.int(0, 1, 1/3))) method cut(x, quantile(x, seq.int(0, 1, 1/3))) does not work.