Skip to content

Instantly share code, notes, and snippets.

View valentinitnelav's full-sized avatar
🏠
Working from home

Valentin Ștefan valentinitnelav

🏠
Working from home
View GitHub Profile
@valentinitnelav
valentinitnelav / Check_taxa_names_Taxonstand&wikitaxa.R
Last active January 3, 2018 16:36
Check some taxa names with Taxonstand & wikitaxa
# -----------------------------------------------------------------------------
# Example to check some taxa names with Taxonstand & wikitaxa
# -----------------------------------------------------------------------------
my_sp <- fread("Output/taxa_to_check_VS.csv")
my_sp
# taxa
# Thereianthus_spicatus
# Eriocnema_fulva
# Hebe_macrocarpa
# Aspalathus_cymbriformis
library(ggplot2)
library(ggsci) # for cool palettes
# read data
my_data <- read.csv("data/chickengrowthdiet.csv")
str(my_data)
# Diet should not be numeric but factor (or categorical)
my_data$Diet <- factor(my_data$Diet)
# -------------------------------------
@valentinitnelav
valentinitnelav / CI_lm_ggplot.R
Created November 24, 2017 12:27
plot confidence intervals for linear model with ggplot using geom_smooth
#####################################################
# CI-s for linear model with ggplot
#####################################################
library(ggplot2)
# -------------------------------------
# Use simulated data from Mick Wu
# -------------------------------------
set.seed(1)
setwd("share/")
getwd()
my_data <- read.table("data/drunkwalks_data.txt", header = TRUE)
plot(my_data)
aggreg <- table(my_data$SEX, my_data$DOMINANT_SIDE)
rownames(aggreg) <- c("female", "male")
colnames(aggreg) <- c("left-handed", "right-handed")
@valentinitnelav
valentinitnelav / closest_geodesic_distance_parallel_foreach_example.R
Last active August 29, 2017 12:38
closest geodesic distance with doParallel and foreach - example
# Example of using foreach parallel loop
# This should work both on Linux and Windows without any modifications.
# for an interesting intro, check:
# http://bgc.yale.edu/sites/default/files/ParallelR.html
library(foreach)
library(doParallel)
# Prepare cluster
@valentinitnelav
valentinitnelav / Euclidean_buffer_distortions.R
Created August 2, 2017 22:20
Euclidean buffer - distortions
require(rgeos)
require(sp)
require(plotKML)
# Generate a random grid-points for a (almost) global bounding box
b.box <- as(raster::extent(120, -120, -60, 60), "SpatialPolygons")
proj4string(b.box) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
set.seed(2017)
pts <- sp::spsample(b.box, n=100, type="regular")
plot(pts@coords)
@valentinitnelav
valentinitnelav / make_GeodesicBuffer.R
Last active April 12, 2018 02:47
Geodesic buffer for point data
make_GeodesicBuffer <- function(XY.dg, dg.step=5, dst.m, crs){
#######################################################################################################
## Function to make a circle-buffer around given points (long-lat coordinates)
## Is different from rgeos::gBuffer() by the fact that it allows the user to create
## a geodesic buffer with a width expressed in metric units.
## Otherwise the user needs to project and apply an Euclidian buffer with rgeos::gBuffer(),
## which will introduce distortions that vary greatly with latitude and the radius of the circle buffer.
## See also my question addressed here:
## https://gis.stackexchange.com/questions/250389/euclidean-and-geodesic-buffering-in-r
##
@valentinitnelav
valentinitnelav / XML_read_tbl.R
Created April 8, 2017 19:02
Read <table> HTML tag with {XML} library
# Read <table> HTML tag with {XML} library
# ====================================================
# Load library
library(XML)
# =======================
# Read the web page [accessed 08-Apr-2017]
# =======================
link <- "http://www.theplantlist.org/1.1/statistics/"
@valentinitnelav
valentinitnelav / rvest_read_tbl.R
Last active April 9, 2017 08:32
Read <table> HTML tag with {rvest} using CSS selectors
# Read <table> HTML tag with {rvest} using CSS selectors
# ====================================================
# Load library
library(rvest)
# =======================
# Read the web page [accessed 08-Apr-2017]
# =======================
link <- "http://www.theplantlist.org/1.1/statistics/"
@valentinitnelav
valentinitnelav / rvest_Read_div.R
Last active April 8, 2017 16:34
Read <div> HTML tag with {rvest} using CSS selector
# Read <div> HTML tag with {rvest} using CSS selector
# ====================================================
# Load library
library(rvest)
# -----------------------
# Read the web page
# -----------------------
link <- "http://www.adirondacklakessurvey.org/alscrpt.inc.php?alscpond=020225B&pname=ALLEGANY%20BROOK%20POND"