Use of R built-in data mpg and library ggplot2

(a) Bar Graph for maufacturer

Names of manufacturers should be in 90 degree angle.

ggplot(mpg, aes(x = manufacturer)) +
  geom_bar() +
  theme(axis.text.x = element_text(angle = 90)) +
  labs(title = "mpg Manufacturer Counts")

(b) Bar Graph for year

ggplot(mpg, aes(x = as.factor(year))) +
  geom_bar() +
  labs(title = "mpg Year Counts", x = "Year")

(c) Density Curves for displ, cty, hwy for each cyl level

ggplot(mpg, aes(x = displ, color = as.factor(cyl))) +
  geom_density() +
  labs(title = "Density Curves for `displ` by `cyl`", color = "cyl")

ggplot(mpg, aes(x = cty, color = as.factor(cyl))) +
  geom_density() +
  labs(title = "Density Curves for `cty` by `cyl`", color = "cyl")

ggplot(mpg, aes(x = hwy, color = as.factor(cyl))) +
  geom_density() +
  labs(title = "Density Curves for `hwy` by `cyl`", color = "cyl")

(d) Side-By-side Boxplots for displ by cyl

ggplot(mpg, aes(x = as.factor(cyl), y = displ, fill = as.factor(cyl))) +
  geom_boxplot() +
  labs(title = "Boxplots for `displ` by `cyl`") +
  theme(legend.position = "none")