import the library and load the dataset

library(ggplot2)
data(mtcars)

converting all the data in the column into factors of different levels

mtcars$cyl <-as.factor(mtcars$cyl)

the data in mtcars dataset is used to create histogram then using facet_warp of cyl columns the data.

ggplot(mtcars,aes(x= mpg))+
  geom_histogram(binwidth = 2,fill='blue',color='black')+
  facet_wrap(~cyl)+
  labs(title="distrubution of mpg across diffrent cylinders",x="mpg",y="frequency")+
  theme_minimal()