Module # 8 Correlation Analysis and ggplot2
Issaiah Jennings
Module # 8 Correlation Analysis and ggplot2
I used correlation analysis through scatter plots to explore relationships between different variables in the mtcars dataset.
In this analysis, we use scatter plots to explore relationships in the mtcars dataset. The focus is on how the grid layout, as suggested by Few, makes comparing multiple plots easier.
We created plots for hp (horsepower) vs mpg (miles per gallon), wt (weight) vs mpg, and disp (displacement) vs mpg. The grid layout places these plots side by side, making patterns and correlations more noticeable and reducing the need for back-and-forth comparison.
For example, the hp vs mpg plot shows that higher horsepower tends to lower mpg, while the wt vs mpg plot shows heavier cars get worse mileage. The grid layout helps make these trends clearer and emphasizes the importance of organizing visuals to improve analysis.
This approach supports Few’s idea of prioritizing visual clarity over overwhelming the viewer with too much information.
> # Load necessary libraries
> library(ggplot2)
> library(gridExtra)
>
> # Use mtcars dataset
> data(mtcars)
>
> # Create scatter plots with regression lines
> p1 <- ggplot(mtcars, aes(x=hp, y=mpg)) +
+ geom_point() +
+ geom_smooth(method = "lm", color = "white") + # Add white regression line
+ ggtitle("HP vs MPG") +
+ theme_minimal()
>
> p2 <- ggplot(mtcars, aes(x=wt, y=mpg)) +
+ geom_point() +
+ geom_smooth(method = "lm", color = "white") + # Add white regression line
+ ggtitle("Weight vs MPG") +
+ theme_minimal()
>
> p3 <- ggplot(mtcars, aes(x=disp, y=mpg)) +
+ geom_point() +
+ geom_smooth(method = "lm", color = "white") + # Add white regression line
+ ggtitle("Displacement vs MPG") +
+ theme_minimal()
>
> # Arrange them in a grid
> grid.arrange(p1, p2, p3, ncol=2)
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
>
In this analysis, we use scatter plots to explore relationships in the mtcars dataset. The focus is on how the grid layout, as suggested by Few, makes comparing multiple plots easier.
We created plots for hp (horsepower) vs mpg (miles per gallon), wt (weight) vs mpg, and disp (displacement) vs mpg. The grid layout places these plots side by side, making patterns and correlations more noticeable and reducing the need for back-and-forth comparison.
For example, the hp vs mpg plot shows that higher horsepower tends to lower mpg, while the wt vs mpg plot shows heavier cars get worse mileage. The grid layout helps make these trends clearer and emphasizes the importance of organizing visuals to improve analysis.
This approach supports Few’s idea of prioritizing visual clarity over overwhelming the viewer with too much information.


Comments
Post a Comment