The packages

Install the devtools package if not installed:

> install.packages("devtools")

Install the viparc package from GitHub:

> devtools::install_github("choisy/viparc")

Load the packages needed (install them beforehand if they are not already installed).

> library(viparc) # heat_map
> library(readxl) # read_excel
> library(dplyr)  # %>%, distinct, filter, transmute

The data

Reading the data from file, deleting the duplicated records (e.g. cycle 1, farm 78, week 6 and cycle 1, farm 62, week 7):

> chicken_farms <-
+   read_excel("Working_Dataset_220118.xlsx", "Sheet1") %>%
+   distinct()

The figures

To draw the heatmaps, we’ll use the function heat_map from the viparc package. To see how to use this figure, read the help of this function:

> ?heat_map

Below, we see some examples using this function. Let’s see for instance the respiratory infections for the first cycle:

> chicken_farms %>%
+   filter(CYCLE == 1) %>% # selecting data from cycle 1
+   transmute(space   = FARMCODE, # next 4 lines is reformating of data
+             time    = WEEK,
+             disease = SRespiratory,
+             drug    = AntibioticUse) %>%
+   heat_map(xlab = "week",
+            ylab = "farm",
+            col_na = "lightgrey", # the color of non surveyed weeks
+            col_surv_no_dis = "blue", # the color of surveyed weeks with no disease
+            col_surv_dis = "red", # the color of surveyed weeks with disease
+            pch = 1) # the point type use for representing drug use (here open circle)

Note that the we need to rename the variables of the data frame before feeding it to the heat_map function. Same code with different options to represent diarrhoea:

> chicken_farms %>%
+   filter(CYCLE == 1) %>%
+   transmute(space   = FARMCODE,
+             time    = WEEK,
+             disease = SDiarrhoea,
+             drug    = AntibioticUse) %>%
+   heat_map(xlab = "week",
+            ylab = "farm",
+            col_na = "lightgrey",
+            col_surv_no_dis = "lightblue",
+            col_surv_dis = "pink",
+            pch = 3) # here, representing the use of antibiotics with a cross

If one wants to represent all the cycles together, this can be done this way by use FARMCYCLE instead of FARMCODE for the space variable of the input data frame (and not selecting any particular site):

> chicken_farms %>%
+   transmute(space   = FARMCYCLE,
+             time    = WEEK,
+             disease = SDiarrhoea,
+             drug    = AntibioticUse) %>%
+   heat_map(xlab = "week",
+            ylab = "farm",
+            col_na = "lightgrey",
+            col_surv_no_dis = "lightblue",
+            col_surv_dis = "pink",
+            pch = 20)