Skip to content

Commit

Permalink
Merge pull request #266 from danlwarren/develop
Browse files Browse the repository at this point in the history
Fixing plots
  • Loading branch information
danlwarren authored Aug 12, 2024
2 parents 04a8031 + d8ad17c commit 7b18829
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions R/enmtools.bc.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ enmtools.bc <- function(species, env = NA, test.prop = 0, report = NULL, overwri

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -255,14 +255,14 @@ enmtools.bc <- function(species, env = NA, test.prop = 0, report = NULL, overwri
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.dm.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ enmtools.dm <- function(species, env = NA, test.prop = 0, report = NULL, nback =

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -254,14 +254,14 @@ enmtools.dm <- function(species, env = NA, test.prop = 0, report = NULL, nback =
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ enmtools.gam <- function(species, env, f = NULL, test.prop = 0, k = 4, nback = 1

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -289,14 +289,14 @@ enmtools.gam <- function(species, env, f = NULL, test.prop = 0, k = 4, nback = 1
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ enmtools.glm <- function(species, env, f = NULL, test.prop = 0, eval = TRUE, nba

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -314,14 +314,14 @@ enmtools.glm <- function(species, env, f = NULL, test.prop = 0, eval = TRUE, nba
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.maxent.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ enmtools.maxent <- function(species, env, test.prop = 0, nback = 1000, env.nback

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -297,14 +297,14 @@ enmtools.maxent <- function(species, env, test.prop = 0, nback = 1000, env.nback
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ enmtools.rf <- function(species, env, f = NULL, test.prop = 0, eval = TRUE, nbac

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -274,14 +274,14 @@ enmtools.rf <- function(species, env, f = NULL, test.prop = 0, eval = TRUE, nbac
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
6 changes: 3 additions & 3 deletions R/enmtools.rf.ranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ enmtools.rf.ranger <- function(species, env, f = NULL, test.prop = 0, eval = TRU

env.training.plot <- ggplot(rts.env.training, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.model.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on training data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand All @@ -286,14 +286,14 @@ enmtools.rf.ranger <- function(species, env, f = NULL, test.prop = 0, eval = TRU
if(test.prop > 0){
test.plot <- ggplot(rts.geog.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in geographic space on test data")) +
theme(plot.title = element_text(hjust = 0.5))

env.test.plot <- ggplot(rts.env.test, aes(x = .data$AUC, fill = "density", alpha = 0.5)) +
geom_histogram(binwidth = 0.05) +
geom_vline(xintercept = model.evaluation@auc, linetype = "longdash") +
geom_vline(xintercept = env.test.evaluation@auc, linetype = "longdash") +
xlim(-0.05,1.05) + guides(fill = "none", alpha = "none") + xlab("AUC") +
ggtitle(paste("Model performance in environment space on test data")) +
theme(plot.title = element_text(hjust = 0.5))
Expand Down
20 changes: 10 additions & 10 deletions R/enmtools.vip.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ enmtools.vip <- function(model, metric = "roc_auc", nsim = 10, method = "permute
if("permute" %in% method){

if(inherits(model, c("enmtools.maxent")) & verbose == FALSE){
invisible(capture.output(output[["permute"]] <- vip::vi_permute(thismodel,
feature_names = feature_names,
train = train,
target = target,
metric = metric,
pred_wrapper = pred_wrapper,
event_level = "second",
nsim = nsim,
keep = TRUE)))
invisible(capture.output(output[["permute"]] <- vip::vi_permute(thismodel,
feature_names = feature_names,
train = train,
target = target,
metric = metric,
pred_wrapper = pred_wrapper,
event_level = "second",
nsim = nsim,
keep = TRUE)))
} else {
output[["permute"]] <- vip::vi_permute(thismodel,
feature_names = feature_names,
Expand Down Expand Up @@ -239,7 +239,7 @@ enmtools.vip <- function(model, metric = "roc_auc", nsim = 10, method = "permute
geom_histogram(bins = 20) +
theme_bw() +
geom_hline(yintercept = 0, color = "grey") +
viridis::scale_fill_viridis(name = "Variable", option = "D", discrete = TRUE, direction = -1) +
viridis::scale_fill_viridis(name = "Variable", option = "D", discrete = TRUE) +
facet_grid(rows = vars(fct_reorder(.data$Variable, .data$Importance, .desc = TRUE)), switch = "y") +
ylab("Variable") +
ggtitle("Variable importance, FIRM method") +
Expand Down

0 comments on commit 7b18829

Please sign in to comment.