0

I have created a plot using the following code:

ggplot(Data, aes(x=damMean, y=progenyMean)) + 
    geom_point()

enter image description here

I want to overlay on the plot a regression line of the form: y = 69.88 + 5.58*x

I tried to do so by adding the following:

ggplot(Data, aes(x=damMean, y=progenyMean)) + 
    geom_point() + 
    geom_smooth(method = "lm", formula = y~69.88+5.58*x)

But this doesn't add a line to the plot.

Is this possible to do using ggplot?

3
  • + geom_abline(slope=5.58, intercept=69.88) Commented Aug 25, 2021 at 16:59
  • @DaveArmstrong this doesn't seem to have worked. There isn't any error message but the abline doesn't show on the graph Commented Aug 25, 2021 at 17:03
  • 1
    Just posted an answer that works for me. I think the problem is that the regression line is not actually in the window. For example, 5.58*40 + 69.88=289.88. So, the line will contain the point (40,289.88). Your y-axis only goes to around 110, so the line is not contained within the plotting region. Commented Aug 25, 2021 at 17:10

1 Answer 1

3

Here's an example with some fake data:

mydat <- tibble(x=runif(100, 40, 90), 
                y = 80 + 5.5*x + rnorm(100, 0, 10))

ggplot(mydat, aes(x=x, y=y)) + 
  geom_point() + 
  geom_abline(slope=5.58, intercept=69.88)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

That looks great. Is there a reason why my geom_abline(slope=5.58, intercept=69.88) isn't showing on the plot?
See comment above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.