So I am trying to add a simple equation to my graph using the text function in R but for some reason its not working.
This is how I generated my randon simulated data:
a <- 5
b <- 7
sigma <- 3
x <- runif(100, min = 0, max = 50)
n <- length(x)
y <- a + b * x + rnorm(n, 0, sigma)
fakeData <- data.frame(x, y)
Then I plugged in the data frame and added a regression line like so.
ggplot(data = fakeData, aes(y, x)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
labs(x = "random uniform distribution from range 0 - 50.",
y = "Linear model points based on the Uniform dist",
title = "Fake data simulation")
Which results in a graph like this
Now all I want to do is add the equation of the line to the graph using the text function but for some reason, R just seems to be throwing errors at me. I tried googling the issue but I wasnt able to resolve it. I tried this method also but the lack of documentation is appalling I have no idea what the guy was doing in the function.