Skip to content

Commit

Permalink
ggplot wrappers for scfm rasters
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Jun 18, 2024
1 parent c4428e9 commit 7d7b3c5
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 5 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Description: The original fire model is described by Cumming et al. (1998),
URL: https://scfmutils.predictiveecology.org,
https://github.com/PredictiveEcology/scfmutils,
https://predictiveecology.github.io/scfmutils/
Date: 2024-06-05
Version: 0.0.13.9002
Date: 2024-06-18
Version: 0.0.13.9003
Authors@R: c(
person("Steve", "Cumming", email = "[email protected]",
role = c("aut")),
Expand Down Expand Up @@ -42,7 +42,9 @@ Imports:
SpaDES.tools (>= 2.0.0),
stats,
terra,
tools
tidyterra,
tools,
viridis
Suggests:
bcdata,
googledrive,
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export(hatP0)
export(makeAndExecuteDesign)
export(makeDesign)
export(pTE)
export(plot_ageMap)
export(plot_burnMap)
export(plot_fireRegimePolys)
export(plot_fireRegimeRas)
export(plot_flammableMap)
export(prepInputsFireRegimePolys)
export(qTE)
export(qqTE)
Expand Down Expand Up @@ -53,8 +57,11 @@ importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_sf)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_fill_brewer)
importFrom(ggplot2,scale_fill_discrete)
importFrom(ggplot2,scale_fill_distiller)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme_bw)
Expand Down Expand Up @@ -104,4 +111,6 @@ importFrom(terra,res)
importFrom(terra,setValues)
importFrom(terra,unwrap)
importFrom(terra,values)
importFrom(tidyterra,geom_spatraster)
importFrom(tools,file_path_sans_ext)
importFrom(viridis,scale_fill_viridis)
85 changes: 83 additions & 2 deletions R/plot_wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,87 @@ plot_fireRegimePolys <- function(fireRegimePolys) {

ggplot(fireRegimePolys) +
geom_sf(aes(fill = PolyID)) +
scale_fill_discrete() +
theme_minimal()
scale_fill_discrete() + ## TODO: use same palette as plot_fireRegimeRas ??
theme_bw()
}

#' Plot fire regime raster
#'
#' @param x `SpatRaster` object corresponding to a fire regime raster
#'
#' @param title character, the plot title
#'
#' @return `ggplot` object
#'
#' @export
#' @importFrom ggplot2 ggplot ggtitle scale_fill_brewer theme_bw
#' @importFrom tidyterra geom_spatraster
plot_fireRegimeRas <- function(x, title) {
ggplot() +
geom_spatraster(data = terra::as.factor(x)) +
scale_fill_brewer(palette = "Paired", type = "qual", na.value = "transparent") +
ggtitle(title) +
theme_bw()
}

#' Plot age map
#'
#' @param x `SpatRaster` object corresponding to stand age or time since disturbance map
#'
#' @param title character, the plot title
#'
#' @param maxAge the maximum age to plot
#'
#' @return `ggplot` object
#'
#' @export
#' @importFrom ggplot2 ggplot ggtitle scale_fill_distiller theme_bw
#' @importFrom tidyterra geom_spatraster
plot_ageMap <- function(x, title, maxAge) {
x[x > maxAge] <- maxAge

ggplot() +
geom_spatraster(data = x) +
scale_fill_distiller(palette = "Greens", direction = 1, na.value = "transparent") +
ggtitle(title) +
theme_bw()
}

#' Plot burn maps
#'
#' @param x `SpatRaster` object corresponding to a current or cumulative burn map.
#'
#' @param title character, the plot title
#'
#' @return `ggplot` object
#'
#' @export
#' @importFrom ggplot2 ggplot ggtitle theme_bw
#' @importFrom tidyterra geom_spatraster
#' @importFrom viridis scale_fill_viridis
plot_burnMap <- function(x, title) {
ggplot() +
geom_spatraster(data = x) +
scale_fill_viridis(na.value = "transparent") +
ggtitle(title) +
theme_bw()
}

#' Plot flammable map
#'
#' @param x `SpatRaster` object corresponding to a flammability map.
#'
#' @param title character, the plot title
#'
#' @return `ggplot` object
#'
#' @export
#' @importFrom ggplot2 ggplot ggtitle scale_fill_distiller theme_bw
#' @importFrom tidyterra geom_spatraster
plot_flammableMap <- function(x, title) {
ggplot() +
geom_spatraster(data = x) +
scale_fill_distiller(palette = "RdBu", na.value = "transparent") +
ggtitle(title) +
theme_bw()
}
21 changes: 21 additions & 0 deletions man/plot_ageMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/plot_burnMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/plot_fireRegimeRas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/plot_flammableMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d7b3c5

Please sign in to comment.