library(quadtree)
habitat <- terra::rast(system.file("extdata", "habitat.tif", package="quadtree"))
# create quadtree
qt <- quadtree(habitat, split_threshold = .1, adj_type = "expand")
#####################################
# DEFAULT
#####################################
# default - no additional parameters provided
plot(qt)
#####################################
# CHANGE PLOT EXTENT
#####################################
# note that additional parameters like 'main', 'xlab', 'ylab', etc. will be
# passed to the default 'plot()' function
# crop extent to the original extent of the raster
plot(qt, crop = TRUE, main = "cropped")
# crop and don't plot NA cells
plot(qt, crop = TRUE, na_col = NULL, main = "cropped")
# use 'xlim' and 'ylim' to zoom in on an area
plot(qt, xlim = c(10000, 20000), ylim = c(20000, 30000), main = "zoomed in")
#####################################
# COLORS AND BORDERS
#####################################
# change border color and width
plot(qt, border_col = "transparent") # no borders
plot(qt, border_col = "gray60") # gray borders
plot(qt, border_lwd = .3) # change line thickness of borders
# change color palette
plot(qt, col = c("blue", "yellow", "red"))
plot(qt, col = hcl.colors(100))
plot(qt, col = c("black", "white"))
# change color transparency
plot(qt, alpha = .5)
plot(qt, col = c("blue", "yellow", "red"), alpha = .5)
# change color of NA cells
plot(qt, na_col = "lavender")
# don't plot NA cells at all
plot(qt, na_col = NULL)
# change 'zlim'
plot(qt, zlim = c(0, 5))
plot(qt, zlim = c(.2, .7))
#####################################
# SHOW NEIGHBOR CONNECTIONS
#####################################
# plot all neighbor connections
plot(qt, nb_line_col = "black", border_col = "gray60")
# don't plot connections to NA cells
plot(qt, nb_line_col = "black", border_col = "gray60", na_col = NULL)
#####################################
# LEGEND
#####################################
# no legend
plot(qt, legend = FALSE)
# increase right margin size
plot(qt, adj_mar_auto = 10)
# use 'legend_args' to customize the legend
plot(qt, adj_mar_auto = 10,
legend_args = list(lgd_ht_pct = .8, bar_wd_pct = .4))
Run the code above in your browser using DataLab