Hi. I am unable to add a regression line to my plot. I would appreciate your advice. Thank you.
anscombe <- data.frame(cbind(x1=c(10,8,13,9,11,14,6,4,12,7,5),
y1=c(8.04,6.95,7.58,8.81,8.33,9.96,7.24,4.26,10.84,4.82,5.68)))
library(ggplot2)
p1 <- ggplot(anscombe) +
geom_point(aes(x1, y1), color = "darkorange", size = 1.5) +
scale_x_continuous(breaks = seq(0,20,2)) +
scale_y_continuous(breaks = seq(0,12,2)) +
expand_limits(x = 0, y = 0) +
labs(x = "x1", y = "y1",
title = "Dataset 1" ) +
theme_bw() +
geom_smooth(method="lm", formula = y1 ~ x1, data= anscombe, col="blue", se=FALSE)
p1
Error: stat_smooth requires the following missing aesthetics: x and y
Backtrace:
x
- +-(function (x, ...) ...
- -ggplot2:::print.ggplot(x)
- +-ggplot2::ggplot_build(x)
- -ggplot2:::ggplot_build.ggplot(x)
-
\-ggplot2:::by_layer(function(l, d) l$compute_statistic(d, layout))
-
\-ggplot2:::f(l = layers[[i]], d = data[[i]])
-
\-l$compute_statistic(d, layout)
-
\-ggplot2:::f(..., self = self)
-
\-self$stat$compute_layer(data, params, layout)
-
\-ggplot2:::f(..., self = self)
-
\-ggplot2:::check_required_aesthetics(...)
Execution halted