Yes, if you want to plot averages, you can either summarize the data first and pass the summarized data to ggplot, or you can use the stat_summary function within ggplot to calculate the means. Here are examples with the mtcars data. Note that I've used geom_col instead of geom_bar. geom_col() is equivalent to geom_bar(stat="identity").
library(tidyverse)
mtcars %>%
group_by(cyl, am) %>%
summarise(mpg=mean(mpg, na.rm=TRUE)) %>%
ggplot(aes(x=factor(cyl), y=mpg, fill=factor(am))) +
geom_col(colour="black", position="dodge") +
scale_y_continuous(expand=expansion(c(0,0.05))) +
theme_bw()

mtcars %>%
ggplot(aes(x=factor(cyl), y=mpg, fill=factor(am))) +
stat_summary(fun=mean, geom="col", position="dodge", colour="black") +
scale_y_continuous(expand=expansion(c(0,0.05))) +
theme_bw()

For future reference, stat_summary allows you to calculate additional statistics from the raw data. For example, below we add both the mean and bootstrapped 95% confidence intervals. You can always calculate any statistics outside of ggplot and then use ggplot to visualize them, but stat_summary can sometimes be more convenient, depending on what you're trying to do:
library(tidyverse)
mtcars %>%
ggplot(aes(x=factor(cyl), y=mpg, colour=factor(am))) +
stat_summary(fun.data=mean_cl_boot, geom="pointrange",
position=position_dodge(0.3)) +
scale_y_continuous(limits=c(0,NA), expand=expansion(c(0,0.05))) +
theme_bw()

Created on 2021-11-06 by the reprex package (v2.0.1)