Skip to content

Instantly share code, notes, and snippets.

View markgrujic's full-sized avatar

markgrujic

  • Melbourne, Australia
View GitHub Profile
@markgrujic
markgrujic / reflowPlotOutput.R
Created July 9, 2018 01:38
plots that flow??
library(shiny)
# example data
df <-
as.data.frame(matrix(rnorm(250), nrow=25)) %>%
rownames_to_column(var = "Year") %>%
mutate(Year = as.numeric(Year))
# Define UI for application that draws a histogram
@markgrujic
markgrujic / missRanger
Created December 19, 2018 22:38
missRanger returning OOB error
function (data, maxiter = 10L, pmm.k = 0L, seed = NULL, verbose = 1, returnOOB = F, ...){
if (verbose > 0) {
cat("\nMissing value imputation by chained tree ensembles\n")
}
stopifnot(is.data.frame(data), dim(data) >= 1L, is.numeric(maxiter),
length(maxiter) == 1L, maxiter >= 1L, is.numeric(pmm.k),
length(pmm.k) == 1L, pmm.k >= 0L, !(c("formula", "data",
"write.forest", "probability", "split.select.weights",
"dependent.variable.name", "classification") %in%
names(list(...))))
@markgrujic
markgrujic / turbo_palette_R.R
Last active August 22, 2019 00:31
Adaptation of Google AI turbo palette for R
# Turbo colour ramp from:
# https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html?m=1
turbo_palette <-
colorRampPalette(
rgb(
matrix(
c(0.18995, 0.07176, 0.23217, 0.19483, 0.08339, 0.26149, 0.19956, 0.09498, 0.29024, 0.20415, 0.10652, 0.31844, 0.20860, 0.11802, 0.34607, 0.21291, 0.12947, 0.37314,
0.21708, 0.14087, 0.39964, 0.22111, 0.15223, 0.42558, 0.22500, 0.16354, 0.45096, 0.22875, 0.17481, 0.47578, 0.23236, 0.18603, 0.50004, 0.23582, 0.19720, 0.52373,
0.23915, 0.20833, 0.54686, 0.24234, 0.21941, 0.56942, 0.24539, 0.23044, 0.59142, 0.24830, 0.24143, 0.61286, 0.25107, 0.25237, 0.63374, 0.25369, 0.26327, 0.65406,
# devtools::install_github("tylermorganwall/rayshader")
library(rayshader)
library(raster)
# replace these with your rasters
r_shadow <- raster("to_shadow.tif")
r_elev <- raster("to_elev.tif")
# resample elevation raster to extent/res of shadow raster
r_elev <- resample(r_elev, r_shadow, method='bilinear')
@markgrujic
markgrujic / mining_stats_2020.R
Last active March 1, 2021 08:03
Quick summary of mining exploration stats up to EOY 2020
library(tidyverse)
library(hues)
library(priceR)
library(readxl)
# get the file
download.file(
url = "https://www.abs.gov.au/statistics/industry/mining/mineral-and-petroleum-exploration-australia/dec-2020/8412005.xls",
destfile = "8412005.xls"
)