Code/06-base_mice_plot_func.R

#function for base_mouse_plot
#Anthony
#March2020
require(ggplot2)
library(extrafont)
# this just simply reduces long name to "Times" as in code below
windowsFonts(Times = windowsFont("TT Times New Roman"))

#Summarise ggplot axis etc
base_mice_plot <- function(mouse_N_144_summary = mouse_N_144_summary){

require(tufte)
require(extrafont)
require(ggplot2)

ggplot(mouse_N_144_summary,
                     aes(
                       y = N,
                       col = Control,
                       shape = Valley,
                       fill = Control,
                       x = Date
                     )) +

# backgroud layout
geom_rect(aes(xmin=ymd('2000-01-01'),xmax = ymd('2000-12-31'),ymin = -Inf,ymax = Inf), colour = "grey90", fill = "grey90") +
geom_rect(aes(xmin=ymd('2002-01-01'),xmax = ymd('2002-12-31'),ymin = -Inf,ymax = Inf), colour = "grey90", fill = "grey90") +
geom_rect(aes(xmin=ymd('2004-01-01'),xmax = ymd('2004-12-31'),ymin = -Inf,ymax = Inf), colour = "grey90", fill = "grey90") +

#axis labels
xlab(expression(paste("Time", "(", italic(t), ")"))) +
ylab(expression(paste("Mouse abundance ", " (", italic(N[jt]), ")"))) +

#themes
theme_tufte() +
  theme_bw() +
  theme(strip.background = element_blank(),
        strip.text.y = element_blank(),

        plot.title = element_text(hjust = 0, size=24, family = "Times", color="black", margin = margin(t = 10, b = 10)),
        plot.subtitle=element_text(size=16, face="italic", color="black"),

        legend.position = "right",
        legend.key = element_blank(),
        legend.background = element_rect(fill="white", size=1),
        legend.key.size=unit(1,"cm"),
        legend.text = element_text(colour = "black", size =10, family = "Times"),
        legend.title = element_text(colour = "black", size =10, family = "Times"),

        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.spacing = unit(2, "lines"),
        panel.border = element_blank(),

        axis.title.y = element_text(colour = "black",size =20, family = "Times", angle = 90),
        axis.title.x = element_text(colour = "black", size =20, family = "Times"),
        axis.text.y=element_text(colour = "black",size = 20, family = "Times"),
        axis.text.x = element_text(colour = "black", size =20, family = "Times"),

        axis.ticks.x = element_line(size = 1),
        axis.ticks.y = element_line(size = 1),
        axis.line.x = element_line(size = 1),
        axis.line.y = element_line(size = 1),

        strip.text = element_text(face="bold",colour = "black",size =14, family = "Times"))

} #end function


#test
#base_mice_plot
davan690/beech-publication-wr documentation built on March 29, 2020, 11:09 a.m.