# Load required library
library(ggplot2)
# Create histogram of mpg from mtcars
ggplot(mtcars, aes(x = mpg)) +
geom_histogram(binwidth = 2, fill = "steelblue", color = "black") +
labs(
title = "Distribution of Miles Per Gallon (mpg) in mtcars",
x = "Miles Per Gallon (mpg)",
y = "Count"
) +
theme_minimal()
To save the image:
r
Copy code
ggsave("mtcars_mpg_histogram.png", width = 6, height = 4)
Reflection:
For this assignment, I used ChatGPT to help me create a histogram of the mpg variable in the mtcars dataset using ggplot2 in R. I asked it for example code, and it generated a clean and workable starting point. I copied the code into RStudio, ran it, and the plot worked right away, which made the process smooth. I then made a few changes, like adjusting the bin width and theme, to make the chart easier to read. The only real challenge was deciding what visual adjustments looked best, but trying different options helped me understand the code better. Overall, ChatGPT felt useful it's a good tool that helped me get started faster and focus on improving the final result.
Comments
Post a Comment