- The goal of this app is for users to highlight eligible cars from the mtcars data set by toggling two variables
- 1: transmission type (manual vs. automatic)
- 2: Miles per Gallon (mpg)
2024-03-02
# Load the mtcars dataset
data(mtcars)
# Rename columns with more descriptive names
colnames(mtcars) <- c("Car_Name", "MPG", "Cylinders", "Displacement",
"Horsepower", "Weight", "Acceleration", "Model_Year",
"Origin", "Transmission")
# Remove columns "Car_Name", "Origin", "Model_Year", "NA"
mtcars_filtered <- mtcars[, !colnames(mtcars) %in% c("Car_Name", "Origin",
"Model_Year", NA)]
# Apply summary function to the modified dataset
summary(mtcars_filtered)
## MPG Cylinders Displacement Horsepower ## Min. :4.000 Min. : 71.1 Min. : 52.0 Min. :2.760 ## 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5 1st Qu.:3.080 ## Median :6.000 Median :196.3 Median :123.0 Median :3.695 ## Mean :6.188 Mean :230.7 Mean :146.7 Mean :3.597 ## 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0 3rd Qu.:3.920 ## Max. :8.000 Max. :472.0 Max. :335.0 Max. :4.930 ## Weight Acceleration Transmission ## Min. :1.513 Min. :14.50 Min. :3.000 ## 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:3.000 ## Median :3.325 Median :17.71 Median :4.000 ## Mean :3.217 Mean :17.85 Mean :3.688 ## 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:4.000 ## Max. :5.424 Max. :22.90 Max. :5.000
# Load the mtcars dataset
data(mtcars)
# Filter the dataset for manual and automatic transmissions
mtcars_manual <- mtcars[mtcars$am == 1, ]
mtcars_automatic <- mtcars[mtcars$am == 0, ]
# Create a boxplot comparing mpg for manual and automatic transmissions
boxplot(mpg ~ am, data = mtcars,
main = "MPG Comparison by Transmission Type",
xlab = "Transmission Type",
ylab = "Miles Per Gallon",
col = c("blue", "red"),
names = c("Automatic", "Manual"))
# Fit a linear regression model model <- lm(mpg ~ wt + cyl + as.factor(am), data = mtcars) # Plot the observed vs. fitted values plot(mtcars$mpg, fitted(model), xlab = "Observed MPG", ylab = "Fitted MPG", main = "Observed vs. Fitted MPG (using Weight, Cylinders and Trans. type") # Add a reference line with slope 1 (ideal fit) abline(a = 0, b = 1, col = "red")