r – While running ggplot2 command, geom smooth is not working

I am giving a small portion of my task that gives me problem.


title: “Untitled”
author: “G. A”
date: “2022-09-05”
output: html_document

knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
ggplot(mpg,x = displ, y = hwy) + geom_point( ) 
#This command is working
ggplot(mpg,x = displ, y = hwy) + geom_point( ) + geom_smooth()
#But this command is not working

I have downloaded all the required packages.

The error message was

> ### your code here
> ggplot(mpg,x = displ, y = hwy) + geom_point( ) + geom_smooth()
`geom_smooth()` using method = 'loess' and formula 'y ~ x' Error in `check_required_aesthetics()':
! stat_smooth requires the following missing aesthetics: x and y
>

Read more here: Source link