我调查了StatQuantile$compute_group
事实证明你可以指定xreg
论证如下:
ggplot(mtcars, aes(hp, disp)) +
geom_point() +
geom_quantile(quantiles = 0.5, aes(group = factor(gear), colour = factor(gear)),
xseq = min(mtcars$hp):max(mtcars$hp))
Result
这是代码
statQuantile$compute_group
<ggproto method>
<Wrapper function>
function (...)
f(...)
<Inner function (f)>
function (data, scales, quantiles = c(0.25, 0.5, 0.75), formula = NULL,
xseq = NULL, method = "rq", method.args = list(), lambda = 1,
na.rm = FALSE)
{
try_require("quantreg", "stat_quantile")
if (is.null(formula)) {
if (method == "rqss") {
formula <- eval(substitute(y ~ qss(x, lambda = lambda)),
list(lambda = lambda))
qss <- quantreg::qss
}
else {
formula <- y ~ x
}
message("Smoothing formula not specified. Using: ", deparse(formula))
}
if (is.null(data$weight))
data$weight <- 1
if (is.null(xseq)) { # <-------------------------------
xmin <- min(data$x, na.rm = TRUE)
xmax <- max(data$x, na.rm = TRUE)
xseq <- seq(xmin, xmax, length.out = 100)
}
grid <- new_data_frame(list(x = xseq))
if (identical(method, "rq")) {
method <- quantreg::rq
}
else if (identical(method, "rqss")) {
method <- quantreg::rqss
}
else {
method <- match.fun(method)
}
rbind_dfs(lapply(quantiles, quant_pred, data = data, method = method,
formula = formula, weight = weight, grid = grid, method.args = method.args))
}