R/raw-uniform-plots.R

##final script for figure 2-4 Davidsonetal2019
#Anthony Davidson
#oct2019

# libraries needed
source("./R/r-packages-needed.R", echo = FALSE)
source("./R/theme_raw_fig3s.r", echo = FALSE)
source("./R/davidson_2019_theme.r", echo = FALSE)
source("./R/Davidson_2019_Data_wrangling.R")
# fig.3.plot.seed.sum.final

# jitter everything the same is harrrrrd
location.move <- position_dodge(width = 30)

# plot
plot.final.f3.1 <- ggplot(p.design2,
                              aes(
                                y = cum.seed,
                                col = Rats,
                                shape = Valley,
                                fill = Control,
                                x = Date
                              ),
                              size = 7) +
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") +

geom_errorbar(aes(ymin = lcl.slog, ymax = ucl.slog, width = 0), lwd = 0.4, col = "black", position = location.move, alpha = 0.7) +

geom_line(col = "grey50") +
geom_point(aes(y = cum.seed,
                                x = Date
                              ),alpha = 0.7, size = 3, stroke = 1.25, position = location.move) +
xlab(expression(paste("Time", "(", italic(t), ")"))) +
ylab(expression(paste("Available seed "," ", "(", italic(Seed[jt]), ")"))) +
scale_color_manual(name = "Stoat Control",
                     values = c("black", "white", "white")) +

  scale_shape_manual(name = "Ecosystem",
                     values = c(24, 21)) +

  scale_size_manual(name = "Rat Control", values = c(2.5, 3, 2.5)) +
  # manually define the fill colours

  scale_fill_manual(name = "Stoat Control",
    values = c("white", "black", "white")) +




  # Remove fill legend and replace the fill legend using the newly created size
  guides(
    col = "none",
    size = guide_legend(override.aes = list(
      shape = c(15,0),alpha = 1
    )),
    shape = guide_legend(override.aes = list(
      shape = c(24, 21), size = 4
    )),
    fill = guide_legend(override.aes = list(
      col = c("white", "black"),shape = c("square"),
      size = 4
    ))
  ) +

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 = "none",
        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 =16, family = "Times"),
        legend.title = element_text(colour = "black", size =16, 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"))

plot.final.f3.1

## ----new-mice------------------------------------------------------------
# plot raw seed
fig.3.N <-
  ggplot(p.design2,
                     aes(
                       y = N,
                       col = Rats,
                       shape = Valley,
                       fill = Control,
                       x = Date
                     )) +
  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") +

  geom_errorbar(aes(ymin = lcl.slog, ymax = ucl.slog, width = 0), lwd = 0.7, col = "black", position = location.move, alpha = 0.7) +

  geom_line(col = "grey50") +
  geom_point(aes(y = N,
                                x = Date
                              ),size = 5, stroke = 1.25, position = location.move) +
xlab(expression(paste("Time", "(", italic(t), ")"))) +
ylab(expression(paste("Mouse abundance ", " (", italic(N[jt]), ")"))) +
  scale_color_manual(name = "Stoat Control",
                     values = c("black", "white", "white")) +

  scale_shape_manual(name = "Ecosystem",
                     values = c(24, 21)) +

  scale_size_manual(name = "Rat Control", values = c(2.5, 3, 2.5)) +
  # manually define the fill colours

  scale_fill_manual(name = "Stoat Control",
    values = c("white", "black", "white")) +




  # Remove fill legend and replace the fill legend using the newly created size
  guides(
    col = "none",
    size = guide_legend(override.aes = list(
      shape = c(15,0),alpha = 1
    )),
    shape = guide_legend(override.aes = list(
      shape = c(24, 21), size = 4
    )),
    fill = guide_legend(override.aes = list(
      col = c("white", "black"),shape = c("square"),
      size = 4
    ))
  ) +

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 = "none",
        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 =16, family = "Times"),
        legend.title = element_text(colour = "black", size =16, 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"))

fig.3.N



## ----new-rats
rat.plot <- ggplot(p.design2, aes(y = N,col = Rats,shape = Valley,fill = Control,x = Date)) +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") +

   geom_errorbar(aes(ymin = lcl.slog, ymax = ucl.slog, width = 0), lwd = 0.7, col = "black", position = location.move) +

  geom_line(data = rat.mean,
    aes(y = mean.rat,
        x = Date),
    size = 0.95,
    col = "grey50", position = location.move) +

  geom_point(data = rat.mean,aes( y = mean.rat,      col = Rats,
      shape = Valley,
      fill = Control,
      x = Date
    ),size = 6 , position = location.move) +

  xlab(expression(paste("Time", "(", italic(t), ")"))) +

  ylab(expression(atop(paste("Minimum "," ", " number"," "),
                       paste(" ", "of"," ",
                             "rats"," ","(",italic(R[jt]),")"))) ) +
  scale_color_manual(name = "Stoat Control",
                     values = c("black", "white", "white")) +

  scale_shape_manual(name = "Ecosystem",
                     values = c(24, 21)) +

  scale_size_manual(name = "Rat Control", values = c(2.5, 3, 2.5)) +
  # manually define the fill colours

  scale_fill_manual(name = "Stoat Control",
    values = c("white", "black", "white")) +




  # Remove fill legend and replace the fill legend using the newly created size
  guides(
    col = "none",
    size = guide_legend(override.aes = list(
      shape = c(15,0),alpha = 1
    )),
    shape = guide_legend(override.aes = list(
      shape = c(24, 21), size = 4
    )),
    fill = guide_legend(override.aes = list(
      col = c("white", "black"),shape = c("square"),
      size = 4
    ))
  ) +
  xlab(expression(paste("Time", "(", italic(t), ")"))) +

  ylab(expression(atop(paste("Minimum "," ", " number"," "),
                       paste(" ", "of"," ",
                             "rats"," ","(",italic(R[jt]),")"))) ) +
  # scale_y_continuous(expand = c(0,0.01),breaks = seq(-4,4,1)) +
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 = "none",
        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 =16, family = "Times"),
        legend.title = element_text(colour = "black", size =16, 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"))


rat.plot





## ----message=FALSE, warning=FALSE----------------------------------------
# save csv file
write.csv(p.design2, "C://Code/data/seed-summary-data-june2019.csv")

# export plot for example vignette
#desktop
#png("C://Code/beech-publication-wr/figs/plot.final.f3.1.png")
#laptop
# png("C://Code/beech-publication-wr/test.seedp.png")
#
plot.final.f3.1
# dev.off()

write.csv(p.design2, "C://Code/data/mouse_summary_data.csv")
# export plot for example vignette
#desktop
# png("C://Code/beech-publication-wr/figs/mice.plot.png")
#laptop
# png("C://GIT/beech-publication-wr/figs/mice_plot.png")
#laptop
# png("C://Code/simple-anova-beech/figs/mouse_plot.png")
fig.3.N
# dev.off()
# export data
write_csv(plot.dat.all1, "C://Code/data/plot_all_data1.csv")
# write_csv(out.final, "./data/final-outputs.csv")
write_csv(abund.dat5, "C://Code/data/abundance5.csv")

# export plot for example vignette
# png("C://GIT/beech-publication-wr/figs/rat_plot.png")
fig.3.rat
# dev.off()

# png("C://Code/simple-anova-beech/figs/rat_plot.png")
rat.plot
# dev.off()
davan690/beech-publication-wr documentation built on March 29, 2020, 11:09 a.m.