Plotting of gapminder dataset

I want to create the top 5 country's time series graph of life expectancy using the gapminder dataset. But I am getting error.
library(tidyverse)
library(gapminder)
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
gapminder<-gapminder %>%
clean_names()
country_wise_exp<-gapminder %>%
group_by(country,year) %>%
summarise(mean_exp=mean(life_exp))
#> summarise() has grouped output by 'country'. You can override using the .groups argument.
country_wise_exp %>%
head(5) %>%
ggplot(country_wise_exp)+geom_point(mapping = aes(year,life_exp))+theme_economist()
#> Error: Mapping should be created with aes() or aes_().
Created on 2021-11-18 by the reprex package (v2.0.1)

Some comments about your code

  1. your code
    country_wise_exp<-gapminder %>% group_by(country,year) %>% summarise(mean_exp=mean(life_exp))
    effectively did nothing. If you group by country and year, there is just 1 data point, and you are doing mean for that 1 single point. For example, for country Afghanistan and year 1952, lifeExp is 28.8. I think, you mean to group by country only.
  2. For your code,
    ggplot(country_wise_exp)+geom_point(mapping = aes(year,life_exp))+theme_economist()
    country_wise_exp does not have any column life_exp, but mean_exp.