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 with `binwidth`.
Plot 2: Improve the histogram of Average Temperature by Month
Plot 2 Code
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
Plot 3 Code
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"))
Plot 3 Output
p3
Plot 4: Side by Side Boxplots in Gray Scale
Plot 4 Code
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: Create a polar bar plot
Plot 5 Code
p5 <-ggplot(data = airquality) +geom_bar(aes(x = Ozone_Bin, fill = Ozone_Bin), show.legend =FALSE, width =1) +theme(aspect.ratio =1) +coord_polar() +labs(title ="Polar Bar Plot of Ozone Levels",x ="Ozone Levels (ppb)",y ="Frequency",caption ="Data source: New York State Department of Conservation and the National Weather Service" ) +theme_minimal()
Plot 5: Create a bar-like graph - Polar Plot
PLot 5 Code
bar <-ggplot(data = diamonds) +geom_bar(aes(x = clarity, fill = clarity), show.legend =FALSE, width =1) +theme(aspect.ratio =1)bar +coord_polar()
Essay
This is a polar bar chart, sometimes called a “rose chart.” Think of it as a regular bar chart that’s been wrapped around a circle. Instead of bars going up and down, they spread out from the center, with each segment’s length showing its value.
This plot shows how many diamonds fall into different “clarity” groups. Most diamonds are in the ‘SI1’ and ‘VS2’ clarity levels (the big slices). Very few diamonds are ‘I1’ (lowest clarity) or ‘IF’ (perfect clarity) (the tiny slices). Basically, it shows that most diamonds are somewhere in the middle for clarity.
I used R’s ggplot2 package.
I told it to make a bar chart of clarity from your diamonds data.
Then, the coord_polar() command was used to turn that regular bar chart into the circular one you see.