Code/figure_one_simulated_plot_function.R

# ----- # data - simulated here --------------------
# options to add simple csv
# data
sim.dat <- read_csv("./data/simulated_data.csv")
# can also be simulated using ...

# Visual para
arrow.length <- 40
touchoff.distance <- 10 # distance between data and start of arrow
arrowhead.size <- 3 # in millimeters
time.loc <- as.character()

# seed data
points.dat <- tibble(
  prediction = as.factor(c("A", "C", "B", "D")),
  value = as.numeric(c(15, 88, 108, 60)),
  date = as.Date(c("1999-08-20", "2000-05-01", "2000-09-13", "2000-12-25")))

## season labels
season_labels <- labels1 <-  c("Summer", "Autumn", "Winter", "Spring", "Summer", "Autumn", "Winter", "Spring")

## masting factor
Masting_labels <- labels2 <-  c("", "", "Non-mast year", "", "", "", "Mast year", "")

#date
date_labels <- as.Date(as.character(c("1999-02-01","1999-05-01","1999-08-01","1999-11-01","2000-02-01","2000-05-01","2000-08-01","2000-11-01","2001-02-01","2001-05-01","2001-08-01","2001-11-01")))




## ----orginal-plot--------------------------------------------------------
#plot
pseed <- ggplot(sim.dat, aes(y = beech.seed, x = date)) +
  geom_rect(aes(xmin=ymd("2000-12-31"),xmax = ymd('1999-12-31'), ymin = -Inf, ymax = Inf), fill = "grey90")+
  geom_line(aes(y = beech.seed, x = date), size = 1.1, col = "grey50", lty = 3) +
  geom_point(aes(y = beech.seed, x = date, fill = control), alpha = 1, stroke = 1.5, shape = 22, size = 4.5, col = "black", fill = "black") +
  geom_point(aes(y = beech.seed, x = date), alpha = 0.5, stroke = 1.5, shape = 25, size = 2,col = "black", fill = "white") +
  xlab("") +
  ylab(expression(paste("Seed ", "(" ,italic(S[jt]),")"))) +

  scale_y_continuous(expand = c(0.05, 0.05)) +
  scale_x_date(breaks = date, date_labels =  labels1, expand = c(0.05, 0.05)) +
  # scale_fill_manual(value ss = c("black")) +

  annotate("text", x=as.Date('2000-05-15'), y = 2000,
           label = "Masting year", size = 4, colour = "black", family = "Times") +
  annotate("text", x=as.Date('1999-07-30'), y = 2000,
           label = "Non-mast year", size = 4, colour = "black", family = "Times") +
  annotate("text", x=as.Date('2001-03-30'), y = 2000,
           label = "Non-mast", size = 4, colour = "black", family = "Times") +

  theme_new() +
  theme(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 =12, family = "Times", angle = 90),
    axis.text.y=element_text(colour = "black",size = 14, family = "Times"),

    axis.title.x = element_blank(),
    axis.text.x = element_blank(),

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

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

    axis.line.y = element_line(size = 1))


# pseed


# reset labels
# build points data
# tibble my life
arrow.length <- 10
touchoff.distance <- 10 # distance between data and start of arrow
arrowhead.size <- 3 # in millimeters
time.loc <- as.character()

# Imported data
# sim.dat

sim.dat.no <- filter(sim.dat, control == "no.stoats") %>%
  droplevels()

sim.dat.yes <- filter(sim.dat, control == "stoats") %>%
  droplevels()


pmice <- ggplot(sim.dat, aes(y = value, x = date)) +

  geom_rect(aes(xmin=ymd("2000-12-31"),xmax = ymd('1999-12-31'), ymin = -Inf, ymax = Inf), fill = "grey90") +

  geom_line(aes(group = control), size = 1.1, col = "grey50", lty = 3) +

  geom_point(data = sim.dat.yes, aes(y = value, x = date),  shape = 22, size = 5, col = "black", fill = "black") +
  geom_point(data = sim.dat.no, aes(y = value, x = date),  shape = 25, size = 5,col = "black", fill = "white") +

  xlab("Time (t)") +
  ylab(expression(paste("Mice"," ", "(" ,italic(N[jt]),")"))) +

  scale_y_continuous(expand = c(0.05, 0.05)) +
  scale_x_date(breaks = date, date_labels =  labels1, expand = c(0.05, 0.05)) +

  # scale_fill_manual(values = c("white", "black")) +

  scale_colour_manual(name = "Stoat control",
                      labels = c("Yes", "No"),
                      values = c("black","white")) +

  scale_fill_manual(name = "Stoat control",
                    labels = c("Yes", "No"),
                    values = c("black","white")) +


  geom_segment(data = points.dat, aes(x = date, y = value,
                                      xend = date, yend = value + touchoff.distance + arrow.length),
               arrow = arrow(length = unit(arrowhead.size, "mm"), ends = "last"), size = 1.25, colour = "red") +

  geom_label(data = points.dat, aes(x = date, y = value - touchoff.distance, label = prediction),
             nudge_x = 20,
             nudge_y = 40)  +

  theme_new()+
  theme(legend.position = c(0.1,0.5),
        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 =14, family = "Times", angle = 90, vjust =  1),
        axis.title.x = element_blank(),
        axis.text.y=element_text(colour = "black",size = 14, family = "Times"),
        axis.text.x = element_text(colour = "black",size = 12, family = "Times", vjust = 1),

        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"))

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