Skip to content

Instantly share code, notes, and snippets.

View Andtise's full-sized avatar
🌏
Focusing

Fengyu Fu Andtise

🌏
Focusing
  • Beijing Normal University
View GitHub Profile
@Andtise
Andtise / bivarRasterPlot.R
Created December 20, 2023 08:31 — forked from scbrown86/bivarRasterPlot.R
Make a bivariate plot using raster data and ggplot2
# The function that produces the colour matrix
colmat <- function(nbreaks = 3, breakstyle = "quantile",
upperleft = "#0096EB", upperright = "#820050",
bottomleft = "#BEBEBE", bottomright = "#FFE60F",
xlab = "x label", ylab = "y label", plotLeg = TRUE,
saveLeg = FALSE) {
# TODO - replace any tidyr, dplyr etc. functions with data.table #
library(tidyverse)
require(ggplot2)
require(classInt)
@Andtise
Andtise / as.data.table.r
Created October 6, 2023 09:38 — forked from etiennebr/as.data.table.r
Transform raster or terra object to data.table
#' Transform raster to data.table
#'
#' @param x Raster* object
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed
#' @param optional logical. If `TRUE`, setting row names and converting column names (to syntactic names: see make.names) is optional
#' @param xy logical. If `TRUE`, also return the spatial coordinates
#' @param centroids logical. If TRUE return the centroids instead of all spatial coordinates (only relevant if xy=TRUE)
#' @param sepNA logical. If TRUE the parts of the spatial objects are separated by lines that are NA (only if xy=TRUE and, for polygons, if centroids=FALSE
#' @param ... Additional arguments (none) passed to `raster::as.data.frame`
#'