Skip to content

Commit

Permalink
Fixing ecospat niche plots
Browse files Browse the repository at this point in the history
This was an easy one - we used to have a cast of the rasters to SpatRasters, but now they're SpatRasters to begin with so I just had to cut those bits out.
  • Loading branch information
danlwarren committed Jan 15, 2024
1 parent 6b210e6 commit 6427819
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/enmtools.ecospat.bg.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste("Ecospat identity test:", species.1$species.name, "vs.", species.2$species.name)) +
theme(plot.title = element_text(hjust = 0.5))

sp1.bg.points <- as.data.frame(terra::rast(sp1.niche$Z), xy = TRUE)
sp1.bg.points <- as.data.frame(sp1.niche$Z, xy = TRUE)
colnames(sp1.bg.points) <- c("X", "Y", "Density")
sp1.bg.plot <- ggplot(data = sp1.bg.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand All @@ -129,7 +129,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste(species.1$species.name, "available environment")) +
theme(plot.title = element_text(hjust = 0.5))

sp1.env.points <- as.data.frame(terra::rast(sp1.niche$z.uncor), xy = TRUE)
sp1.env.points <- as.data.frame(sp1.niche$z.uncor, xy = TRUE)
colnames(sp1.env.points) <- c("X", "Y", "Density")
sp1.env.plot <- ggplot(data = sp1.env.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand All @@ -138,7 +138,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste(species.1$species.name, "occurrence in environment space")) +
theme(plot.title = element_text(hjust = 0.5))

sp1.env.corr.points <- as.data.frame(terra::rast(sp1.niche$z.cor), xy = TRUE)
sp1.env.corr.points <- as.data.frame(sp1.niche$z.cor, xy = TRUE)
colnames(sp1.env.corr.points) <- c("X", "Y", "Density")
sp1.env.plot.corr <- ggplot(data = sp1.env.corr.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand All @@ -147,7 +147,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste(species.1$species.name, "occurrence scaled by availability")) +
theme(plot.title = element_text(hjust = 0.5))

sp2.bg.points <- as.data.frame(terra::rast(sp2.niche$Z), xy = TRUE)
sp2.bg.points <- as.data.frame(sp2.niche$Z, xy = TRUE)
colnames(sp2.bg.points) <- c("X", "Y", "Density")
sp2.bg.plot <- ggplot(data = sp2.bg.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand All @@ -156,7 +156,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste(species.2$species.name, "available environment")) +
theme(plot.title = element_text(hjust = 0.5))

sp2.env.points <- as.data.frame(terra::rast(sp2.niche$z.uncor), xy = TRUE)
sp2.env.points <- as.data.frame(sp2.niche$z.uncor, xy = TRUE)
colnames(sp2.env.points) <- c("X", "Y", "Density")
sp2.env.plot <- ggplot(data = sp2.env.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand All @@ -165,7 +165,7 @@ enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers =
ggtitle(paste(species.2$species.name, "occurrence in environment space")) +
theme(plot.title = element_text(hjust = 0.5))

sp2.env.corr.points <- as.data.frame(terra::rast(sp2.niche$z.cor), xy = TRUE)
sp2.env.corr.points <- as.data.frame(sp2.niche$z.cor, xy = TRUE)
colnames(sp2.env.corr.points) <- c("X", "Y", "Density")
sp2.env.plot.corr <- ggplot(data = sp2.env.corr.points, aes(y = .data$Y, x = .data$X)) +
geom_raster(aes_string(fill = "Density")) +
Expand Down

0 comments on commit 6427819

Please sign in to comment.