Engine Size vs Highway MPG

Plot

p1 <- ggplot(mpg, aes(x = displ, y = hwy, color = class,
                      text = paste("Model:", model,
                                   "<br>Displacement:", displ,
                                   "<br>Highway MPG:", hwy))) +
  geom_point(alpha = 0.75, size = 3) +
  labs(title = "Displacement vs Highway MPG by Vehicle Class", x = "Engine Displacement (Liters)", y = "Highway MPG", color = "Class") + theme_bw(base_size = 14)
ggplotly(p1, tooltip = "text")

Average MPG by Class

Plot

p2 <- mpg %>%
  group_by(class) %>%
  summarise(avg_hwy = mean(hwy)) %>%
  arrange(desc(avg_hwy)) %>%
  ggplot(aes(x = reorder(class, avg_hwy), y = avg_hwy)) +
  geom_col(fill = "darkred") +
  labs(title = "Average Highway MPG by Vehicle Class", x = "Vehicle Class", y = "Average Highway MPG") + theme_bw(base_size = 14)
ggplotly(p2, tooltip = c("x", "y"))

Displacement vs Cylinders, Faceted by Manufacturer

Plot

p3 <- ggplot(mpg, aes(x = factor(cyl), y = displ,
                      text = paste("Model:", model,
                                   "<br>Class:", class,
                                   "<br>Displ (L):", displ,
                                   "<br>Cylinders:", cyl))) + geom_jitter(width = 0.2, alpha = 0.7, color = "darkred", size = 2.5) +
  facet_wrap(~manufacturer, ncol = 4) + labs(title = "Displacement vs Cylinders by Manufacturer", x = "Cylinders", y = "Displacement (Liters)") + theme_bw(base_size = 13)
ggplotly(p3, tooltip = "text")