This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Add a logo to a ggplot panel | |
| #' | |
| #' Places a raster image (logo, stamp, watermark) inside a ggplot panel using | |
| #' [ggplot2::annotation_custom()]. Placement is controlled either by a corner | |
| #' shorthand or by explicit coordinates, and sizing uses absolute [grid::unit()] | |
| #' values for predictable results across plot dimensions. | |
| #' | |
| #' @param p A [ggplot2::ggplot()] object. | |
| #' @param logo A path or URL to an image file, a `magick-image` object, or any | |
| #' object accepted by [magick::image_read()]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get_os <- function(){ | |
| sysinf <- Sys.info() | |
| if (!is.null(sysinf)){ | |
| os <- sysinf['sysname'] | |
| if (os == 'Darwin') | |
| os <- "osx" | |
| } else { ## mystery machine | |
| os <- .Platform$OS.type | |
| if (grepl("^darwin", R.version$os)) | |
| os <- "osx" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Calculate Radiative Forcing from CO2 Concentration | |
| #' | |
| #' Calculates the radiative forcing in W m-2 based on changes in CO2 concentration | |
| #' using the formula from Myrhe et al. (1998). | |
| #' | |
| #' The radiative forcing is calculated using the equation: | |
| #' \deqn{\Delta F = 5.35 \times \ln(C/C_0)}{ΔF = 5.35 * ln(C/C0)} | |
| #' | |
| #' @param C numeric vector. Current CO2 concentration in ppm. | |
| #' @param C0 numeric. Reference CO2 concentration in ppm. Default is 280 ppm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' List files on an FTP server | |
| #' | |
| #' Connects to a remote FTP directory and returns the list of file names, | |
| #' optionally filtered by a regular expression pattern. This function is | |
| #' the discovery companion to [ftp_download()]: use it to identify which | |
| #' files exist before deciding what to download. | |
| #' | |
| #' @param url A full FTP or FTPS URL pointing to a directory, e.g. | |
| #' `"ftp://data.example.org/climate/daily/"`. Must start with `ftp://` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Title | |
| #' | |
| #' @param x | |
| #' | |
| #' @return | |
| #' @export | |
| #' | |
| #' @examples | |
| is_integer <- function(x){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Get sunrise and sunset time for any location and date from sunsetsunrise.io API | |
| #' | |
| #' @param lon longitude in decimal degree of the location | |
| #' @param lat latitude in decimal degree of the location | |
| #' @param date a date string in 'yyy-mm-dd' format. | |
| #' | |
| #' @return a tibble with sunset/sunrise time, day length, location timezone and date | |
| #' @export | |
| #' | |
| #' @examples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Default atmospheric CO2 concentration from 1902 to 2099 (updated 01/08/2022) | |
| Year CO2 (ppm by volume) | |
| ============================ | |
| 1902 297.4 | |
| 1905 298.2 | |
| 1912 300.7 | |
| 1915 301.3 | |
| 1924 304.5 | |
| 1926 305.0 | |
| 1929 305.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Generate fixed width file in R | |
| #' @description This simple function creates fixed width file with no | |
| #' extra dependencies. | |
| #' @param justify "l", "r" or something like "lrl" for left, right, left. | |
| #' @examples dt <- data.frame(a = 1:3, b = NA, c = c('a', 'b', 'c')) | |
| #' write_fwf(dt, "test.txt", width = c(4, 4, 3)) | |
| #' @export | |
| write_fwf = function(dt, file, width, | |
| justify = "l", replace_na = "NA") { | |
| fct_col = which(sapply(dt, is.factor)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(terra) # Spatial Data Analysis | |
| library(tidyterra) # 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' | |
| library(ggplot2) # For Data Visualisations Using the Grammar of Graphics | |
| library(rgeoboundaries) # For Political Administrative Boundaries | |
| library(ggspatial) # Spatial Data Framework for ggplot2 | |
| library(ggtext) # Improved Text Rendering Support for 'ggplot2' | |
| library(ggsflabel) # for spatial labeling | |
| x <- terra::rast(x = "/Volumes/OUSMANE/exo_BSD/semis_fin_07/sem0173.rst") | |
| y <- classify(x,c(0,1,2,3,4,5,6,7,8)) |