Hello,
Here is a way of doing this by first calculating the percentages before you use them in the plots
library(tidyverse)
nithin<-tibble::tribble(
~age, ~class_attendance,
6L, "Yes",
6L, "No",
6L, "Yes",
7L, "Yes",
7L, "Yes",
7L, "No",
8L, "No",
8L, "No",
8L, "Yes",
6L, "Yes",
6L, "No",
8L, "No",
7L, "No",
6L, "Yes",
7L, "No",
8L, "Yes",
6L, "Yes",
8L, "No"
)
nithin %>%
mutate(level=if_else(age==6,"Level 1-Age 6",
if_else(age==7,"Level 2-Age 7","Level 3- Age 8"))) %>%
drop_na(class_attendance) %>%
group_by(age) %>%
mutate(perc = sum(class_attendance == "Yes") / n(),
perc = ifelse(class_attendance != "Yes", 1-perc, perc)) %>%
ungroup() %>%
ggplot(aes(class_attendance))+
geom_bar(width=0.5,mapping=aes(fill=class_attendance))+
facet_wrap(~level)+
geom_text(aes(label = paste0(perc %>% round(2) * 100, "%")),
stat = "count", vjust = -0.5)+
theme_minimal()

Created on 2022-03-21 by the reprex package (v2.0.1)
Hope this helps,
PJ