Dataset Visualization

The mtcars dataset contains information about various car models. It includes 32 observations on 11 variables such as miles per gallon (mpg), horsepower (hp), and weight (wt).

We will create a visualization to explore the relationship between mpg (Miles per Gallon) and wt (Weight of the car).

##Visualization

library(ggplot2)
data(mtcars)

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(aes(color = cyl), size = 3) +
  labs( title = "Scatter Plot of MPG vs Weight",
    subtitle = "This plot shows the relationship between car weight (wt) and miles per gallon (mpg)",
    x = "Weight (1000 lbs)",  # X-axis label
    y = "Miles per Gallon (mpg)",  # Y-axis label
    caption = "Data Source: mtcars dataset in R") +
  theme_minimal()

##Data Distribution

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(aes(color = as.factor(cyl), shape = as.factor(gear)), size = 4) +  labs( title = "Scatter Plot of MPG vs Weight with Data Distribution", subtitle = "Points colored by the number of cylinders and shaped by the number of gears", x = "Weight (1000 lbs)", y = "Miles per Gallon (mpg)", caption = "Data Source: mtcars dataset in R") +
  scale_color_manual(values = c("#BFD4DB" , "#A4C3D2", "#78A2CC" )) +  
  scale_shape_manual(values = c(15, 16, 18)) + theme_minimal()