##Problem Description For my final project I wanted to choose something I cared about which is cars and speed, as I am a huge car enthusiast. I am using the automobiles dataset from the lgrdata package in R, it hast 398 cars with 9 variables. My research question is to find out what actually makes a car accelerate faster? I want to know if the horsepower is the main thing or if weight and where the car originated from matters. I also want to see if American, European and Japanese cars accelerate differently compared to each other.
##Related work We have done some similar work in class, especially correlation and multivariate analysis. This project connects to my module 8 correlation project where I had plotted MPG vs weight and used facet_wrap to split the data by cylinder count. The project taught me that one overall trend can hide differences between groups. We also used scatterplot to compare variables moving together and we also talked about how to compare groups while keeping the charts organized. One existing visual analytics project I liked is a “Coffee Orders” sales dashboard on github that I found online. I really liked how it broke the data down into different views instead of just one big chart. I also want to do a similar multi view analysis but focused on car acceleration instead of sales.
##Solution I decided to use Rstudio with ggplot2 and plotly to make four figures. Figure 1 will use a histogram for distrubution, figure 2 uses a scatterplot with a trend line for correlation, figure 3 uses a colored scatterplot for multivariate and figure 4 uses a sorted horizontal bar chart for ranking. I followed Few’s advice by minimizing clutter so I used theme_minimal() throughout the project to keep the colors neutral. In Figure 2 I kept the confidence band because it shows how sure the trend is, but in Figure 3 I dropped it because the three origin groups already make the plot busy enough. That was a trade off for clarity, same as when I removed confidence bands in my Module 8 plot.
##Figure 1: Distrubution of Acceleration Times
ggplot(automobiles, aes(x=acceleration)) +
geom_histogram(bins=20, fill="steelblue", color="white")+
labs(
title="How are acceleration times distributed?",
x= "Acceleration time (seconds to 60 mph)",
y= "Number of cars"
) +
theme_minimal()
##Why I chose this chart: I decided to use a histogram because I am looking at distribution. Histograms aree one of the best way to see how quantitative data is spread out. I used 20 bins because its enough to show the shape without making the bars get too skinny. I kept it minimal and used on solid color so that the data stands out.
##What it shows: The chart shows that most cars accelerate between 12 and 18 seconds. There is a right tail with a few slow cars. But because the data is spread out the way it is it shows there is real variation to explain, which is why I needed the next three charts.
#Figure 2: Correlation Between Horsepower and Acceleration
p2 <- ggplot(automobiles, aes(x=horsepower,y=acceleration))+
geom_point(alpha=0.5,color="steelblue")+
geom_smooth(method="lm",se=TRUE, color="red")+
labs(
title= "More horsepower means faster acceleration (lower time)",
x="Horsepower",
y="Acceleration time(seconds)"
) +
theme_minimal()
ggplotly(p2)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 6 rows containing non-finite outside the scale range
## (`stat_smooth()`).
##Why this chart: I chose the scatterplot with a trend line because I am looking at correlation. Both variables are quantitative, so points make more sense rather than bars. I kept the confidence band because it shows how sure the trend is, but I didnt add extra colors or grids to keep it clean.
##What it shows: The scatterplot shows there is a clear negative relationship. Cars with more horsepower have lower acceleration times, meaning they are faster. The trend line goes down but the points are pretty spread out around the line which tells me horsepower on its own does not explain everything.
#Figure 3:Multivariate View by Origin
ggplot(automobiles, aes(x=horsepower, y=acceleration,color=origin))+
geom_point(alpha= 0.7, size= 2.5)+
scale_color_brewer(palette="Set1")+
labs(
title= "Horsepower vs acceleration, colored by origin",
x="Horsepower",
y="Acceleration time in seconds",
color="Origin"
)+
theme_minimal()
## Warning: Removed 6 rows containing missing values or values outside the scale range
## (`geom_point()`).
##Why this chart: For mutivariate analysis I decided to use color to represent the origin of the car. I intentionally removed the trend line because having 3 different trend lines in one chart would have made it way too messy. That was a trade off for clarity.
##What does it show: American cars (red) have high horsepower but also high acceleration times which suggests they are heavy. Japanese cars (blue) have lower horsepower but still get decent acceleration times. This proves that an overall trend can hide differences between groups.
##Figure 4: Fastest Cars Ranked
fastest<- automobiles %>%
arrange(acceleration) %>%
slice(1:10) %>%
mutate(car_name = reorder (car_name, -acceleration))
ggplot(fastest, aes(x=car_name, y= acceleration))+
geom_col(fill="hotpink")+
coord_flip()+
labs(
title= "Top 10 fastest cars in automobiles dataset",
x=NULL,
y="Acceleration time in seconds"
)+
theme_minimal()
##What chart shows: The top 10 cars is a very small group with tines under 11 seconds, mostly european sports cars. The bars are close in length, which shows that the absolute fastest cars are outliers compared to the rest of the dataset.
##Why this chart: For ranking, a sorted horizontal bar chart is the best choice. The car names are long, so horizontal bars keep them readable. I sorted them from fastest to slowest so you can compare at a glance. I made the bars pink as a personal design choice, but kept everything else minimal so it doesnt distract from the data.
##Discussion
My research Question was whether horsepower and weight affect acceleration. All of the figures show that horsepower matters so much but it is not everything. Origin and weight also play a role which is the same lesson I had learned in Module 8 project when faceting by cylinder count showing different trends per group. The distribution figure 1 shows that there is real variation and the ranking in figure 4 shows the fastest cars are a small group rather than an even spread.
I believe one of my limitations is that I did not run a statistical test, only visual analysis. Another thing is that this dataset is a bit old so it doesnt reflect newer modern cars. But for this project the figures answer the question quite well enough to show the pattern and I beleive the trade offs I made between detail and clarity were well worth it.
##References Dataset: ‘automobiles’ from ‘lgrdata’ package. Visual practices: Few
AI DISCLOSURE: None was used