Home > Software engineering >  Why is geom_smooth not showing in my graph?
Why is geom_smooth not showing in my graph?

Time:12-10

Do you have any idea why this code is not returning a linear regression line on the plot?

ggplot(data = df3, mapping = aes(x = work_growth, y = gdp_growth, col = RegionCode)) 
  geom_point() 
  labs (x= "Growth rate of the working-age population",y = "Growth rate of GDP per capita")  
  geom_smooth(method="lm") 
  theme_classic()   theme(legend.position = "none")

This is plot I get:1

Here is the dataframe I'm working with for reference: enter image description here call using the `regionCode as a color argument

ggplot(data = dat, mapping = aes(x = work_growth, y = gdp_growth)) 
    labs (x= "Growth rate of the working-age population",y = "Growth rate of GDP per capita")  
    geom_smooth(method="lm")  
    geom_point(aes(col=RegionCode)) 
    theme_classic()   theme(legend.position = "none")
  • Related