Formative assessment work

Mosquito Data

Below you will see my attempt at using the mosquito data to produce an annotated box plot. For some reason I had 101 problems with trying to upload the data; this is why I chose to upload individually rather than as part of my group as it would create too many complications. I attempted to convert it into an excel spreadsheet to try that way however unsure on how successful that was. Any tips on how to improve this data upload for next time will be appreciated! Thank you :)

Mosquito

Mosquito data summary

       ID              wing           sex           
 Min.   :  1.00   Min.   :25.16   Length:100        
 1st Qu.: 25.75   1st Qu.:41.42   Class :character  
 Median : 50.50   Median :48.42   Mode  :character  
 Mean   : 50.50   Mean   :48.78                     
 3rd Qu.: 75.25   3rd Qu.:56.24                     
 Max.   :100.00   Max.   :69.82                     

Boxplot

It keeps saying that my data set is not found yet I am able to use and manipulate the data so I’m very confused by this but I’m sure there is a simple fix.

data(mosquitos123)
Warning in data(mosquitos123): data set 'mosquitos123' not found
library(readxl)
mosquitos123 <- read_excel("C:/Users/kplai/OneDrive/Documents/RMDA/mosquitos123.xlsx")


ggplot(mosquitos123, aes(x=wing, y=sex)) +
  geom_boxplot(aes(fill=sex)) +
  labs(title="A Boxplot showing Wing Length (cm) and Gender in Mosquitoes",
       x="Species ID",
       y="Sepal Length (cm)") +
  theme_minimal()

Annotations of the Plot:

  • ggplot(mosquitos123, aes(x=wing, y=sex)):

    • This initializes a ggplot object using the mosquitos123 dataset.

    • aes(x=wing, y=sex) sets the aesthetic mappings: the x-axis will represent wing, and the y-axis will represent sex.

  • geom_boxplot(aes(fill=sex)):

    • This adds a boxplot layer to the plot.

    • aes(fill=sex) specifies that the boxes should be filled based on the sex variable, differentiating between male and female mosquitoes (or whatever the sex variable represents).

  • labs(title="Boxplot of Wing Span by Species", x="Species", y="Wing Length (cm)"):

    • This adds labels to the plot.

    • title sets the title of the plot.

    • x and y label the x-axis and y-axis, respectively.

  • theme_minimal():

    • This applies a minimalistic theme to the plot, removing background grids and emphasizing the data.

Histogram

ggplot(mosquitos123, aes(x = wing, fill = sex)) +
  geom_histogram(position = "identity", alpha = 0.5, bins = 30) +  
  labs(title = "Comparison of Wing Lengths in Males and Females",
       x = "Wing Length",
       y = "Frequency") +
  theme_minimal() +
  scale_fill_manual(values = c("blue", "pink"))  #

Annotations for Histogram

  • aes(x = wing, fill = sex): This sets the wing variable on the x-axis and uses sex to determine the fill color of the bars.

  • geom_histogram(position = "identity", alpha = 0.5, bins = 30):

    • position = "identity": This allows the histograms to overlap.

    • alpha = 0.5: This sets the transparency of the bars so you can see overlapping areas.

    • bins = 30: This specifies the number of bins. You can adjust this number to change the granularity of the histogram.

  • labs(): This function is used to add titles and labels to the axes.

  • theme_minimal(): This applies a minimal theme to the plot.

  • scale_fill_manual(values = c("blue", "pink")): This customizes the fill colors for males and females.