Module # 7 assignment
Issaiah Jennings
Module # 7 assignment
In this post, I tested visual distribution analysis using the mtcars dataset in R, following the recommendation from our textbook to use a grid layout for comparing variables. The mtcars dataset is built into R, so you can easily access it by typing data(mtcars).
I created scatter plots to compare variables like miles per gallon (mpg), weight (wt), and horsepower (hp). By organizing these plots into a grid, I could quickly see the relationships between the variables. Here's the R code I used to generate the plots:
# Load the necessary libraries
install.packages("gridExtra")
library(ggplot2)
library(gridExtra)
# Load the mtcars dataset
data(mtcars)
# Create scatter plots
plot1 <- ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point() + ggtitle("MPG vs Weight")
plot2 <- ggplot(mtcars, aes(x=mpg, y=hp)) + geom_point() + ggtitle("MPG vs Horsepower")
plot3 <- ggplot(mtcars, aes(x=wt, y=hp)) + geom_point() + ggtitle("Weight vs Horsepower")
# Combine plots into a grid
grid.arrange(plot1, plot2, plot3, ncol=2)

Comments
Post a Comment