require(ggthemes)
require(tidyverse)
require(lubridate)
require(extrafont)
#function for theme here for now
# This is currently NOT WORKING
# theme mods
# generating new theme is in this plotting function now
## ----orginal-plot--------------------------------------------------------
output_for_fig_1_func <- function(sim.dat = sim.dat) {
theme_new <- function(base_size = 18,
base_family = "Times",
base_line_size = base_size / 170,
base_rect_size = base_size / 300) {
theme_bw(
base_size = base_size,
base_family = base_family,
base_line_size = base_line_size
) %+replace%
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", angle = 90),
axis.title.x = element_blank(),
axis.text.y=element_text(colour = "black"),
axis.text.x = element_blank(),
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), complete = TRUE) # end of ggplot theme
}## finishin function
##imported data
sim.dat <- sim.dat
## labels
labels1 <- c("Summer", "Autumn", "Winter", "Spring", "Summer", "Autumn", "Winter", "Spring")
labels2 <- c("", "", "Non-mast year", "", "", "", "Mast year", "")
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")))
# reset labels
# build points data
# tibble my life
arrow.length <- 10
touchoff.distance <- 40 # distance between data and start of arrow
arrowhead.size <- 3 # in millimeters
time.loc <- as.character()
sim.dat.no <- filter(sim.dat, control == "no.stoats") %>%
droplevels()
sim.dat.yes <- filter(sim.dat, control == "stoats") %>%
droplevels()
#plot seeds
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 = 0.7,
stroke = 1.5,
shape = 25,
size = 4.5,
col = "black",
fill = "black") +
geom_point(aes(y = beech.seed, x = date), alpha = 1, stroke = 0.7, shape = 25, size = 1,col = "white", fill = "white") +
xlab("") +
ylab(expression(paste("Seed Avaliability "))) +
scale_y_continuous(expand = c(0.05, 0.05)) +
scale_x_date(breaks = sim.dat.no$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") +
annotate("text", x=as.Date('1999-07-30'), y = 2000,
label = "Non-mast year", size = 4, colour = "black") +
annotate("text", x=as.Date('2001-03-30'), y = 2000,
label = "Non-mast", size = 4, colour = "black") +
theme_classic()+
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", angle = 90),
axis.title.x = element_text(colour = "black", angle = 90),
axis.text.y=element_text(colour = "black"),
axis.text.x = element_blank(),
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))
pseed
# 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 = 0.9, col = "grey50", lty = 3) +
geom_point(data = sim.dat.yes, aes(y = value, x = date), alpha = 0.7, shape = 25, size = 5, col = "black", fill = "black") +
geom_point(data = sim.dat.no, aes(y = value, x = date), alpha = 0.7, shape = 25, size = 5,col = "black", fill = "white") +
xlab("Time (t)") +
ylab(expression(paste("Rodent "," ", "Abundance"))) +
scale_y_continuous(expand = c(0.05, 0.05)) +
scale_x_date(breaks = sim.dat.yes$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 = 60) +
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", angle = 90),
axis.title.x = element_text(colour = "black"),
axis.text.y=element_text(colour = "black"),
axis.text.x = element_text(colour = "black"),
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))
# pmice
# makes graphs smaller
result.plot <- cowplot::plot_grid(pseed, pmice ,nrow = 2,
align="v",
labels = c("a)", "b)"),
rel_heights = c(0.8, 1.2)
)
# return(result.plot = result.plot)
} #function end
#example
sim.dat <- read_csv(file = "C://data/simulated_data_v2.csv")
result.plot <- output_for_fig_1_func(sim.dat = sim.dat)
result.plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.