import the library and dataset

library(ggplot2)
data(mpg)

creates a boxplot in ggplot to visualize the distribution of highway mileage (hwy) for different car categories based on the number of cylinders (cyl). It uses a pastel color palette to differentiate the boxes for each cylinder category.

box_plot <- ggplot(mpg,aes(x=factor(cyl),y=hwy,fill=factor(cyl)))+
  geom_boxplot(alpha=0.5)+
  labs(
    title="highway milage distribution by number of cylinder",
    x = " number of cylinders",
    y = " highway milage")+
  theme_minimal()+
  scale_fill_brewer( palette="pastell")
## Warning: Unknown palette: "pastell"

displaying the boxplot

print(box_plot)