Test

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

  1. input CSV
    1. find CSV file and copy as path
    2. go to box, make ssuwre there is {r} and paste path
    3. in box, write “read.csv” and replace \ with \\.
    4. Have the path in the ()
test_df <- read.csv("C:\\Users\\jdesw\\Desktop\\AEON LAB\\R work\\Test\\sdi_richness.csv")
  1. make a new chunk via ctl-alt-i
  2. make a box plot compairing species diversity and habitat type
  3. open and/or install packages
library(ggplot2)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.2
✔ lubridate 1.9.4     ✔ tibble    3.3.0
✔ purrr     1.1.0     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
  1. make a new chunk

  2. for GG plot

    a) first but in file

    b) then doe aesthetic for the inputted file

    c) change colour of boxes by fill.

    d) outside of brackets do a + then press “enter” and add the geom_boxplot to specify the type of plot

    e) now we add figure caption, use quatation amrks for adding labelsand we can use spaces here.

    f) add theme

    1. add theme for title, meaning we adjust the title location from to centered (on a scale of [0, 1].
ggplot(test_df, aes(x = Habitat, y = Mean.SDI, fill = Habitat))+
  geom_boxplot()+
  labs(
    x = "Habitat Type", y = "Mean SDI", title = "SDI by Habitat"
  )+
  theme_classic()+
  theme(plot.title = element_text(hjust = 0.5))

  1. Now save
  2. File -> save all

Now we want to do a scatter plot relating the occurence of scaridae (parrotfish) with pomicentridae (damselfish)

  1. new chunk (and run libraries again in case you closed the document)
  2. New data frame (new excel sheet), we add a %>% (loop) meaning we can modify test_df but the results of the modifications are in the new spreadsheet “Parrot”. Anything after %>% is a modification applied.
  3. Select the columns I want to use (specified after the loop).
Parrot <- test_df %>%
  select(Site, TotalSM, Habitat, Pomacentridae, Scaridae)
  1. now we normalize the species counts by total square meters (*100 means for 100 square meters)
  2. Use the Mutate function, this will new columns to the Parrot spreadsheet
Parrot <- Parrot %>%
  mutate(Damsel = Pomacentridae/TotalSM*100, Parrot = Scaridae/TotalSM*100)
  1. now we graph
  2. make new chunk, copy and paste previous ggplot then make necessary modifications.
ggplot(Parrot, aes(x = Damsel, y = Parrot))+
  geom_point()+
  labs(
    x = "Damselfish", y = "Parrotfish", title = "Parrotfish by Damselfish"
  )+
  theme_classic()+
  theme(plot.title = element_text(hjust = 0.5))

  1. add colour by site and other things

    ggplot(Parrot, aes(x = Damsel, y = Parrot, colour = Habitat)) +
      geom_point(size = 3) +
       geom_smooth(method = lm, se=F)+
      facet_wrap(~Habitat)+
      scale_colour_brewer(palette = "Dark2") +
      labs(
        x = "Damselfish",
        y = "Parrotfish",
        title = "Parrotfish by Damselfish"
      ) +
      theme_classic() +
      theme(plot.title = element_text(hjust = 0.5))
    `geom_smooth()` using formula = 'y ~ x'

  2. save

  3. file -> save all