knitr::opts_chunk$set(fig.width = 9.4, fig.height = 9.4)
library("tidyverse")
library("lubridate")
library("clifro")
library("viridis")
library("ggpubr")
library("here")
library("ChickpeaAscoDispersal")

theme_set(theme_pubclean(base_size = 14))
# Note that GhostScript needs to be installed at the system level for the PS files to be generated.
# MacOS users can use `brew install ghostscript`
# 
# Windows users can follow these directions:
# 1.    Go to the GhostScript website (https://www.ghostscript.com/download/gsdnld.html)
# 2.    Download the windows installer suitable for your machine
# 3.    Run the installer file which you downloaded and follow the prompts
# 4.    After running the installer click the windows "Start" button and type "Edit environment variables for your account" and open
# 5.    In the tab 'Advanced' click the button at the bottom 'Enviroment Variables...'
# 6.    Under 'System variables' find the variable 'Path', select 'Path' and click the 'Edit' button
# 7.    Select a new line and copy the Ghostscript 'bin' folder location into the field.
# 7.1   If you installed ghostscript to the default folder location; then the folder location will likely be "C:\Program Files\gs\gs9.52\bin", the version number (9.52) may differ.
# 8.    Save and exit the environmental variables window


# This chunk is then run only if knitting on new computer that the files have not been generated on
# this is necessary to embed fonts in .eps files for EJPP
library("extrafont")

if (.Platform$OS.type == "windows") {
   font_import(pattern = "arial", prompt = FALSE)
   loadfonts(device = "postscript", quiet = TRUE)
} else {
   font_import(pattern = "Arial", prompt = FALSE)
   loadfonts(device = "postscript", quiet = TRUE)
}

Visualise Counts per Pot

ggplot(lesion_counts, aes(x = m_lesions)) +
   geom_density() +
   xlab("Mean lesion count per plant")

Visualise the Dispersal Data

ggplot(lesion_counts, aes(x = distance,
                          y = m_lesions)) +
   geom_count() +
   scale_size(breaks = c(1, 2, 4, 8)) +
   stat_summary(fun.y = "median",
                geom = "line",
                na.rm = TRUE) +
   stat_summary(
      fun.y = "median",
      colour = "red",
      size = 2,
      geom = "point"
   ) +
   scale_x_continuous(breaks = c(0, 10, 25, 50, 75)) +
   ylim(c(-0.5, 9)) +
   ylab("Mean lesion count values") +
   xlab("Distance (m)") +
   facet_wrap(. ~ SpEv, ncol = 3)
# save a .png to refer to while writing and a .eps for publication submission
ggsave(here::here("man", "figures/Fig2.png"))
ggsave(here::here("man", "figures/Fig2.eps"))
extrafont::embed_fonts(
   file = here::here("man",
                     "figures/Fig2.eps"),
   outfile = here::here("man",
                        "figures/Fig2.eps"),
   options = "-dEPSCrop"
)

Visualise the Rainfall

dat <- left_join(lesion_counts, cleaned_weather, by = c("site", "rep"))

dat %>%
   group_by(SpEv) %>%
   mutate(Hour = floor_date(time, "1 hour")) %>%
   group_by(SpEv, Hour) %>%
   summarize(sum(rainfall)) %>%
   ggplot(aes(x = Hour, y = `sum(rainfall)`)) +
   geom_col() +
   scale_x_datetime(
      "Date (day-month)",
      date_breaks = "day",
      date_labels = "%d-%m",
      date_minor_breaks = "hour",
      guide = guide_axis(check.overlap = TRUE)
   ) +
   ylab("Precipitation (mm)") +
   facet_wrap(. ~ SpEv, ncol = 3, scales = "free_x")

Visualise the Wind Speed and Direction

pw <-
   with(
      dat,
      windrose(
         wind_speed,
         wind_direction,
         SpEv,
         n_col = 3,
         legend_title = "Wind speed (m/s)"
      )
   )
pw +
   scale_fill_viridis_d(name = "Wind Speed (m/s)", direction = -1) +
   xlab("") +
   theme_pubclean()

When inspecting these data, we noted that the wind direction for Curyo was against the direction of spread along the transects, which led to further investigation of the weather data. That investigation is detailed in this analysis.

Heatmap of Lesions Along Transects

heat_dat <-
   lesion_counts %>%
   group_by(SpEv, degrees) %>%
   mutate(summed_count_pot =
             case_when(distance == 0 ~ sum(m_lesions),
                       TRUE ~ m_lesions)) %>%
   filter(m_lesions > 0)

ggplot(data = heat_dat,
       aes(
          x = degrees,
          y = distance,
          colour = summed_count_pot,
          size = summed_count_pot
       )) +
   geom_count(data = subset(heat_dat, distance == 0)) +
   geom_count(data = subset(heat_dat, distance > 0)) +
   scale_colour_viridis_c(
      direction = -1,
      name = "n",
      guide = "legend",
      breaks = c(1, 5, 10, 15, 20)
   ) +
   coord_polar(theta = "x",
               start = 0,
               direction = 1) +
   scale_size(
      range = c(2, 8),
      name = "n",
      breaks = c(1, 5, 10, 15, 20)
   ) +
   scale_x_continuous(
      breaks = c(0, 90, 180, 270),
      expand = c(0, 0),
      limits = c(0, 360),
      labels = c("N", "E", "S", "W")
   ) +
   scale_y_continuous(breaks = c(0, 10, 25, 50, 75),
                      limits = c(0, 75)) +
   ylab("Distance (m)") +
   xlab("Transect") +
   facet_wrap(. ~ SpEv, ncol = 3)
ggsave(here::here("man", "figures/Fig4.png"))
ggsave(here::here("man", "figures/Fig4.eps"))
extrafont::embed_fonts(
   file = here::here("man",
                     "figures/Fig4.eps"),
   outfile = here::here("man",
                        "figures/Fig4.eps"),
   options = "-dEPSCrop"
)


adamhsparks/ChickpeaAscoDispersal documentation built on April 29, 2024, 12:32 p.m.