ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line()
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(se = TRUE)
# If you need the fitting to be done along the y-axis set the orientation
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(orientation = "y")
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(orientation = "y", se = TRUE)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(formula = y ~ x)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(formula = x ~ y)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(formula = y ~ poly(x, 3))
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(formula = x ~ poly(y, 3))
# Instead of rq() we can use rqss() to fit an additive model:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(method = "rqss",
formula = y ~ qss(x, constraint = "D"),
quantiles = 0.5)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(method = "rqss",
formula = x ~ qss(y, constraint = "D"),
quantiles = 0.5)
ggplot(mpg, aes(displ, hwy)) +
geom_point()+
stat_quant_line(method="rqss",
interval="confidence",
se = TRUE,
mapping = aes(fill = factor(after_stat(quantile)),
color = factor(after_stat(quantile))),
quantiles=c(0.05,0.5,0.95))
# Smooths are automatically fit to each group (defined by categorical
# aesthetics or the group aesthetic) and for each facet.
ggplot(mpg, aes(displ, hwy, colour = drv, fill = drv)) +
geom_point() +
stat_quant_line(method = "rqss",
formula = y ~ qss(x, constraint = "V"),
quantiles = 0.5)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_quant_line(formula = y ~ poly(x, 2)) +
facet_wrap(~drv)
# Inspecting the returned data using geom_debug()
gginnards.installed <- requireNamespace("gginnards", quietly = TRUE)
if (gginnards.installed)
library(gginnards)
if (gginnards.installed)
ggplot(mpg, aes(displ, hwy)) +
stat_quant_line(geom = "debug")
if (gginnards.installed)
ggplot(mpg, aes(displ, hwy)) +
stat_quant_line(geom = "debug", fm.values = TRUE)
Run the code above in your browser using DataLab