Skip to content

Instantly share code, notes, and snippets.

View Nowosad's full-sized avatar
🌍

Jakub Nowosad Nowosad

🌍
View GitHub Profile
#------------------------------------------------------------
# REVOLUTION ANALYTICS WEBINAR: INTRODUCTION TO R FOR DATA MINING
# February 14, 2013
# Joseph B. Rickert
# Technical Marketing Manager
#
# BIG DATA with RevoScaleR
#
# Copyright: Revolution Analytics
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style type="text/css">
body {
@Nowosad
Nowosad / index.html
Last active August 29, 2015 14:07 — forked from zross/index.html
<!DOCTYPE html>
<html>
<head>
<title>Leafletmap</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js?2"></script>
<style type="text/css">
body {
#' A qml create function
#'
#' This function creates QGIS-like xml object with random colors based on a group variable
#' @param obj an object of class SpatialPolygonDataFrame or data.frame
#' @param group a grouping variable (colname from obj)
#' @param alpha an alpha value (0-1)
#' @param colors a character vector with colors (hex colors)
#'
#' @return xml object
#'
library(sp)
library(sf)
library(tidyverse)
g = SpatialGrid(GridTopology(c(0, 0), c(1, 1), c(3, 3)))
p = as(g, "SpatialPolygons") %>%
st_as_sf() %>%
mutate(id = row_number()) %>%
as("Spatial")
library(sf)                              
#> Linking to GEOS 3.6.1, GDAL 2.1.4, proj.4 4.9.3
library(spData)                          
library(tmap)                            
                                         
tm_shape(nz) +                           
tm_polygons() +                          
tm_compass(position = c("left", "top")) +
tm_scale_bar() 
@Nowosad
Nowosad / lsm_l_shei2.R
Created May 12, 2018 18:41
lsm_l_shei - test
#' Shannon's Evenness Index
#'
#' @description Evenness of patch types (classes) in the landscape
#'
#' @param landscape Raster* Layer, Stack, Brick or a list of rasterLayers.
#' @return tibble
#'
#' @examples
#' lsm_l_shei(landscape)
#' lsm_l_shei(landscape_stack)
library(gganimate)
#> Loading required package: ggplot2
library(ggplot2)
ggplot(diamonds, aes(cut, carat)) +
        geom_point(col = "red") +
        geom_boxplot() + 
        transition_layers(layer_length = 1, transition_length = 1)
#> Error in `$<-.data.frame`(`*tmp*`, ".phase", value = "raw"): replacement has 1 row, data has 0
@Nowosad
Nowosad / sf_change_class
Created November 27, 2018 15:17
How to change the class of variables within an sf object?
library(sf)
library(dplyr)
library(spData)
str(nz)
# change class for one column
nz2 = nz %>%
mutate(Land_area = as.factor(Land_area))