p1 <- airquality |>ggplot(aes(x=Temp, fill=Month)) +geom_histogram(position="identity")+scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September")) +labs(x ="Monthly Temperatures from May - Sept", y ="Frequency of Temps",title ="Histogram of Monthly Temperatures from May - Sept, 1973",caption ="New York State Department of Conservation and the National Weather Service") #provide the data source
Plot 1 Output
p1
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Plot 2: Improve the histogram of Average Temperature by Month
p2 <- airquality |>ggplot(aes(x=Temp, fill=Month)) +geom_histogram(position="identity", alpha=0.5, binwidth =5, color ="white")+scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September")) +labs(x ="Monthly Temperatures from May - Sept", y ="Frequency of Temps",title ="Histogram of Monthly Temperatures from May - Sept, 1973",caption ="New York State Department of Conservation and the National Weather Service")
Plot 2 Output
p2
Plot 3: Create side-by-side boxplots categorized by Month
p3 <- airquality |>ggplot(aes(Month, Temp, fill = Month)) +labs(x ="Months from May through September", y ="Temperatures", title ="Side-by-Side Boxplot of Monthly Temperatures",caption ="New York State Department of Conservation and the National Weather Service") +geom_boxplot() +scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September"))
Plot3 Output
p3
Plot 4: Side by Side Boxplots in Gray Scale
p4 <- airquality |>ggplot(aes(Month, Temp, fill = Month)) +labs(x ="Monthly Temperatures", y ="Temperatures", title ="Side-by-Side Boxplot of Monthly Temperatures",caption ="New York State Department of Conservation and the National Weather Service") +geom_boxplot()+scale_fill_grey(name ="Month", labels =c("May", "June","July", "August", "September"))
Plot 4 Output
p4
Plot 5: Scatterplot
ggplot(airquality, aes(x = Temp, y = Wind)) +geom_point() +labs(x ="Temperature",y ="Wind Speed",title ="Relationship Between Temperature and Wind Speed",caption ="New York State Department of Conservation and the National Weather Service" )
Esaay
I created a scatterplot to show the relationship between temperature and wind speed. I used scatterplot to compare two numerical variables(Temp, Wind), so I placed temperature on the x-axis and wind speed on the y-axis. Each point on the graph represents one day from the dataset.
From the graph, we can see that the slope is negative, which means that as temperature increases, wind speed tends to decrease. However, the relationship is not very strong because the points are spread out and there are some outliers visible in the plot.This means that temp may influence wind slightly.
To make this plot, I used ggplot() with geom_point() to display the data points. I also used the labs() function to add a title, axis labels, and a caption, following the same format used in the previous examples.