I have some data with headers INTERVAL and DURATION
I am new to R. I want to make a scatterplot and then overlay linear regression
please tell me what I am doing wrong
detach(oldfaithful)
oldfaithful = read.csv("oldfaithful.csv", header=TRUE)
attach(oldfaithful)
n = length(DURATION)
ggplot(oldfaithful, mapping = aes(x = INTERVAL, y = DURATION)) +
geom_point(alpha=.5) +
labs(x="Interval between eruptions in minutes", y="duration of eruption in minutes")+
geom_abline(lm(INTERVAL~DURATION))
Error: `mapping` must be created by `aes()
#### System Information:
- RStudio Edition: Desktop
- RStudio Version: Version 1.4.1717
- OS Version: Windows 10
- R Version:
Use geom_smooth() instead, look at this example using a built-in dataset
library(ggplot2)
ggplot(faithful, mapping = aes(x = waiting, y = eruptions)) +
geom_point(alpha=.5) +
labs(x="Interval between eruptions in minutes", y="duration of eruption in minutes")+
geom_smooth(method = "lm")
#> `geom_smooth()` using formula 'y ~ x'