david lomidze
david lomidze

Reputation: 11

Can't add line on the plot

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

Answers (1)

Axeman
Axeman

Reputation: 35382

  1. You can't use abline with ggplot. Use geom_smooth with method = "lm" instead.

  2. 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.

  3. It's generally not recommended to use attach.

  4. 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

Related Questions