0
votes

Hello I'm trying to use the abline to make a line in my scatterplot, I've tried a few different methods, but I'm not too sure what I'm doing wrong! (Fairly new to R)

enter image description here

edit: The code that I have also tried

plot(data$GRE.Score, data$Chance.of.Admit, main = "Regression Line plot", 
     xlab = "Chance of Admit", ylab = "GRE Score", 
     pch = 19, frame = FALSE)

abline(lm(GRE.Score ~ Chance.of.Admit, data = data), col = "red")
1
I've tried it from that same page as well, however, I get: Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet - IJA

1 Answers

0
votes

I hope this small examples guides you the way:

# dummy data
df <- data.frame(x = 1:100, y = rpois(100, lambda = 4))

# plot
plot(df$x, df$y, main = "Main title",
     xlab = "X axis title", ylab = "Y axis title",
     pch = 19, frame = FALSE)

# linear regression line (can only be called AFTER the plot call)
abline(lm(y ~ x, data = df), col = "blue")
# vertical line that cuts X at 10
abline(v = 10, col = "red")
# horizontal line that cuts Y at 10
abline(h = 10, col = "green")

With the kaggle data:

df <- read.csv("C:/.../Admission_Predict.csv")
# plot
plot(df$GRE.Score, df$Chance.of.Admit, main = "Main title",
     xlab = "X axis title", ylab= "Y axis title",
     pch = 19, frame = FALSE)
abline(lm(Chance.of.Admit ~ GRE.Score, data = df), col = "red")