Project Overview

This report provides an interactive data analysis of car performance characteristics using the mtcars dataset in R. The analysis aims to give insights into the relationship between miles per gallon, horsepower, car weight, and other factors. All visualizations are created using Plotly for interactivity, allowing you to hover over data points for more detail.

Dataset Overview

The mtcars dataset includes information about various car models:

Variable Description
mpg Miles per gallon
cyl Number of cylinders
hp Horsepower
wt Weight (in 1000 lbs)
am Transmission type (0 = Automatic, 1 = Manual)

The goal of this report is to explore the relationships and distributions of these variables.

# Display the first few rows of the dataset
head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

Data Visualizations

1. Relationship between Horsepower and Miles per Gallon

The first chart shows a scatter plot of mpg (miles per gallon) versus hp (horsepower), with color representing the number of cylinders.

fig <- plot_ly(data = mtcars, x = ~hp, y = ~mpg, color = ~factor(cyl), type = 'scatter', mode = 'markers') %>%
  layout(title = "Miles per Gallon vs Horsepower",
         xaxis = list(title = "Horsepower"),
         yaxis = list(title = "Miles per Gallon (MPG)"),
         colorway = c("#636EFA", "#EF553B", "#00CC96"))
fig

Insight: This scatter plot helps in understanding the trade-off between fuel efficiency and engine power. Generally, higher horsepower tends to correlate with lower miles per gallon, especially in cars with more cylinders.

2. Average Miles per Gallon by Cylinder Count

The bar plot below shows the average miles per gallon for each cylinder type.

avg_mpg <- mtcars %>%
  group_by(cyl) %>%
  summarise(avg_mpg = mean(mpg))

fig <- plot_ly(data = avg_mpg, x = ~factor(cyl), y = ~avg_mpg, type = 'bar') %>%
  layout(title = "Average MPG by Cylinder Count",
         xaxis = list(title = "Number of Cylinders"),
         yaxis = list(title = "Average MPG"))
fig

Insight: Cars with fewer cylinders generally achieve higher miles per gallon, indicating better fuel efficiency. This can be useful when choosing vehicles for fuel efficiency.

3. Distribution of Car Weights

The histogram below visualizes the distribution of car weights in the dataset.

fig <- plot_ly(data = mtcars, x = ~wt, type = 'histogram') %>%
  layout(title = "Distribution of Car Weights",
         xaxis = list(title = "Weight (1000 lbs)"),
         yaxis = list(title = "Frequency"))
fig

Insight: The histogram shows that most cars in this dataset have weights clustered in a specific range. Knowing the common weight range can help in evaluating and comparing car models based on size and potential fuel usage.

4. Horsepower by Transmission Type

The box plot below compares the distribution of horsepower across automatic and manual transmission types.

fig <- plot_ly(data = mtcars, y = ~hp, x = ~factor(am), type = 'box') %>%
  layout(title = "Horsepower Distribution by Transmission Type",
         xaxis = list(title = "Transmission Type (0 = Automatic, 1 = Manual)"),
         yaxis = list(title = "Horsepower"))
fig

Insight: Cars with manual transmissions generally show a wider range of horsepower. This insight could help in assessing the performance capabilities of cars with different transmission types.

5. Proportion of Cars by Gear Count

This pie chart illustrates the proportion of cars with different gear counts.

gear_count <- as.data.frame(table(mtcars$gear))
fig <- plot_ly(data = gear_count, labels = ~Var1, values = ~Freq, type = 'pie') %>%
  layout(title = "Proportion of Cars by Gear Count")
fig

Insight: This pie chart indicates which gear counts are most common among the cars in the dataset. This information can be useful for understanding the typical transmission configurations available.

Summary

This report provides insights into car performance metrics in relation to engine size, fuel efficiency, weight, and transmission type. Key findings include:

  • Fuel Efficiency: Cars with fewer cylinders and lower horsepower tend to have better miles per gallon.
  • Weight Distribution: The majority of cars in this dataset fall within a moderate weight range.
  • Transmission and Power: Manual transmission vehicles tend to have higher horsepower variability.

Each interactive visualization provides an opportunity to dive deeper into the data by exploring individual data points.