A Report of Module 03 on Plots

With an emphasis on Part 02 (histograms and box plots)


Begin by reading the desired file into RStudio.
squid <- read.csv("squid.csv")

Histograms


Create a histogram of squid GSI values.
hist(squid$GSI, breaks = 15, col = "hotpink", xlab = "GSI", main = "Squid GSI")

This histogram shows a distribution of squid GSI values in hot pink. Labels for the x-axis and y-axis are specified, and elements like the colors and number of breaks can be altered to change the viewing experience.


Create two separate histograms of GSI values for male and female squid. Don’t forget to add a legend.
hist(squid$GSI[squid$Sex == 2], col = 6, xlab = "GSI", main = "Squid GSI", add = FALSE)
hist(squid$GSI[squid$Sex == 1], col = 4, xlab = "GSI", main = "Squid GSI", add = TRUE)
legend("topright", legend = c("Female", "Male"), fill = c(6, 4), title="Squid Sex")

These histograms overlap the distribution of male squid GSI values with the distribution of female squid GSI values in order to make them easier to compare. The x-axis and y-axis labels can be altered, as well as the colors and number of columns. A legend must be made to specify which histogram pertains to which squid sex.


Box Plots


Create a box plot showing the relationship of squid GSI to the sex of the squid.
boxplot_colors <- c("darkgreen", "darkorange")
boxplot(squid$GSI ~ squid$Sex, data = squid, col = boxplot_colors, xlab = "Sex",
        ylab = "GSI", main = "Squid GSI by Sex")
legend("topleft", legend = c("Female", "Male"), fill = c("darkorange", "darkgreen"), title="Squid Sex")

These side-by-side box plots allow us to see differences between the distribution of GSI in male squid and GSI in female squid. Similar to the histogram, the x-axis and y-axis labels can be altered. A legend must also be made to specify which box plot pertains to which squid sex.


Create a box plot showing the relationship of squid GSI to the locations where the squid were caught.
boxplot_colors2 <- c("hotpink", "darkorange", "darkblue", "lightgreen")
boxplot(squid$GSI ~ squid$Location, data = squid, col = boxplot_colors2, xlab = 
          "Location", ylab = "GSI", main = "Squid GSI by Location")

From these side-by-side box plots, we can gain a better understanding of how squid GSI differs based on the location where the squid were caught. Similar to prior graphics, the labels and colors can be easily altered to meet specific needs. This graphic should have a legend, but based on the given data, it was unclear which number corresponded to which location.