I am trying to make a plot with the equation y=mx+c overlaid on the top. Based on the summary statistics, the intercept is 0.8 and the slope is 2.21. I tried adding this and one from another study with a different colour but it is not populating. Am I doing something wrong?
colA <- c(1, 2, 3, 4, 5)
colB <- c(0.1, 0.5, 0.9, 1.4, 1.9)
df <- as.data.frame(cbind(colA, colB))
model <- lm(colA~colB, data=df)
aov(model)
summary(model)
ggplot(df, aes(x = colA, y = colB)) +
geom_point() +
geom_abline(aes(intercept = 0.8, slope = 2.21, colour="line1"), key_glyph = "path") + #This study
geom_abline(aes(intercept = -0.5, slope = 5.3, colour="line2"), key_glyph = "path") + #another study
scale_colour_manual(values = c("black", "red"),
labels = c("This study", "Another study")) +
theme_bw()
You’ve got the x- and y-axes interchanged. Your model is:
lm(colA~colB, data=df)
, which is predicting colA
(y) using colB
(x).
ggplot(df, aes(x = colB, y = colA)) +
...