Reputation: 11
I'm new in R and I had to create a simple linear regression.
I get only dots but I can't add line to this dots explaining it's rising can someone help me to solve this problem?
[]
Upvotes: 1
Views: 805
Reputation: 35382
You can't use abline
with ggplot
. Use geom_smooth
with method = "lm"
instead.
You are missing a closing parenthesis )
, as is evident by having the +
symbol in the console, which means R is waiting for further input. In the script editor, while your cursor is on the last parenthesis, it is highlighting the parenthesis that it's closing.
It's generally not recommended to use attach
.
You might want to read an introduction to ggplot
and work through some examples.
To get to the plot you wanted, I would write:
ggplot(diamonds, aes(x = log(carat), y = log(price), col = color)) +
geom_point() + geom_smooth(method = 'lm')
Upvotes: 6