stat_smooth standard error curve not complete

Hello!

I'm new to R and am trying to use stat_smooth to add both a smooth line and accompanying standard errors to a plot.

However, the standard errors don't appear to be spanning the entire width of the plot. See here: https://imgur.com/a/G89j7WW

My code is as follows:

Antennate <- ggplot(FemNumeric,
                        aes(x = Mass,
                            y = as.numeric(Antennate))) +
  geom_point(size = 7.5,
             alpha = 1/2) +
  labs( x = "Mass of female cricket (g)",
        y = "Time to antennate (s)",
        title = "Antennation")+
  scale_x_continuous (limits=c(0,1.30), 
                      expand=c(0,0),
                      breaks=seq(0, 1.25, 0.25)) +
  scale_y_continuous(limits=c(0,650), 
                     expand=c(0,0),
                     breaks=seq(0, 600, 100)) +
  theme_classic(base_size = 30) +
  stat_smooth(method = "lm", 
              col = "black") 

fit3 <- lm(Antennate ~ Mass, 
           data = FemNumeric)

I'd appreciate some help in resolving this.

Thank you!

try to run without the limits to the scales if you want to just zoom use coord cartesian

1 Like

Thanks for your help :smiley:

This fixed the standard error problem.

This answer on Stack Overflow provides additional detail on why this happens and why setting limits with coord_cartesian() instead of scale_y_continuous() fixes it.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.