library(ggplot2) p <- qplot(x = wt, y = mpg, data = mtcars) p + geom_abline()
June 29, 2015
library(ggplot2) p <- qplot(x = wt, y = mpg, data = mtcars) p + geom_abline()
p + geom_abline(intercept = 20)
coefficients <- coef(lm(formula = mpg ~ wt, data = mtcars))
p + geom_abline(intercept = coefficients[["(Intercept)"]],
slope = coefficients[["wt"]])
coefficients <- coef(lm(formula = mpg ~ wt, data = mtcars))
p + geom_abline(intercept = coefficients[["(Intercept)"]],
slope = coefficients[["wt"]], color = "red",
size = 2)
p + stat_smooth(method = "lm", se = TRUE)
p + stat_smooth(method = "lm", se = FALSE)
p <- ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) +
geom_point()
df <- data.frame(a = rnorm(n = 10, mean = 25),
b = rnorm(n = 10, mean = 0))
p + geom_abline(mapping = aes(intercept = a, slope = b), data = df)
p + geom_smooth(mapping = aes(group = cyl), method = "lm")
p + geom_smooth(mapping = aes(group = cyl), method = "lm",
fullrange = TRUE)
p + geom_abline(intercept = coefficients[["(Intercept)"]],
slope = coefficients[["wt"]]) + coord_flip()
p + geom_abline(intercept = coefficients[["(Intercept)"]],
slope = coefficients[["wt"]]) + coord_polar()