Skip to content

Instantly share code, notes, and snippets.

View robwschlegel's full-sized avatar

Robert William Schlegel robwschlegel

View GitHub Profile
# Establish the vector scalar for the wind
wind_uv_scalar <- 0.5
# The bottom figure (air)
mg_bottom <- ggplot(data = southern_africa_coast, aes(x = lon, y = lat)) +
# The ocean temperature
geom_raster(data = air_temp, aes(fill = value)) +
# The land mass
geom_polygon(aes(group = group), fill = NA, colour = "black", size = 0.5, show.legend = FALSE) +
geom_path(data = africa_borders, aes(group = group)) +
# False Bay inset
fb <- ggplot(data = sa_shore, aes(x = lon, y = lat)) +
# The land mass
geom_polygon(aes(group = PID),
fill = "grey70", colour = NA, size = 0.5, show.legend = FALSE) +
# The in situ sites
geom_point(data = site_list, shape = 1, size = 3, colour = "black") +
geom_text(data = site_list, aes(label = order), size = 2.3, colour = "red") +
# Text label
geom_text(aes(x = 18.65, y = -34.25, label = "False\nBay"), size = 2.7) +
# Establish the vector scalar for the currents
current_uv_scalar <- 2
# The top figure (sea)
mg_top <- ggplot(data = southern_africa_coast, aes(x = lon, y = lat)) +
# The ocean temperature
geom_raster(data = sea_temp, aes(fill = value)) +
# The bathymetry
stat_contour(data = sa_bathy[sa_bathy$depth < -200 & sa_bathy$depth > -2000,],
aes(x = lon, y = lat, z = depth, alpha = ..level..),
# Devide the reanalysis data
sea_temp <- filter(all_jan1_0.5, variable == "BRAN/temp")
air_temp <- filter(all_jan1_0.5, variable == "ERA/temp")
currents <- filter(all_jan1_0.5, variable == "BRAN/u" | variable == "BRAN/v") %>%
select(-date, -index) %>%
spread(key = variable, value = value) %>%
rename(u = "BRAN/u", v = "BRAN/v")
winds <- filter(all_jan1_0.5, variable == "ERA/u" | variable == "ERA/v") %>%
select(-date, -index) %>%
spread(key = variable, value = value) %>%
## Libraries
library(tidyverse)
library(viridis)
library(gridExtra)
## Data
# South Africa map data
load("../data/southern_africa_coast.Rdata") # Lowres
names(southern_africa_coast)[1] <- "lon"
load("../data/sa_shore.Rdata") # Hires
# Top 10 goat having countries
goats_top <- goats %>%
arrange(desc(value)) %>%
filter(ccode %in% head(unique(ccode), 10))
# Bottom 10
goats_bottom <- goats %>%
arrange(value) %>%
filter(ccode %in% head(unique(ccode), 10))
goats %>%
group_by(year) %>%
select(-ccode, -country.name) %>%
summarise(value = mean(value)) %>%
ggplot(aes(x = year, y = value)) +
geom_boxplot(data = goats, aes(group = year)) +
geom_smooth(method = "lm")
# Load libraries
library(tidyverse)
library(gridExtra)
# Load data
goats <- read_csv("../data/GoatsperCapita_Compact.csv") %>%
filter(year >= 1900)
# Returns
return_bar <- ggplot(data = removals, aes(x = Year, y = Returns)) +
geom_col(aes(fill = Party), colour = "black") +
# geom_smooth(method = "lm", colour = "black") +
labs(x = NULL, y = "Immigrants Returned") +
scale_fill_manual(values = c("slateblue1", "firebrick1")) +
ggtitle("Returns")
# Removals
removal_bar <- ggplot(data = removals, aes(x = Year, y = Removals)) +
# Calculate residuals
green_card_resids <- augment(lm(Number~Year, data = green_card))
green_card_resids <- merge(green_card_resids, party_year, by = "Year")
# Plot them
ggplot(data = green_card_resids, aes(x = Year, y = .resid)) +
geom_col(aes(fill = Party), colour = "black") +
geom_smooth(method = "lm", colour = "black") +
labs(x = NULL, y = "Green Cards Granted") +
scale_fill_manual(values = c("slateblue1", "firebrick1"))