Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Valentin Ștefan valentinitnelav

🏠
Working from home
View GitHub Profile
@valentinitnelav
valentinitnelav / Check_taxa_names_Taxonstand&wikitaxa.R
Last active Jan 3, 2018
Check some taxa names with Taxonstand & wikitaxa
View Check_taxa_names_Taxonstand&wikitaxa.R
# -----------------------------------------------------------------------------
# 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
View chicks_plot.R
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 Nov 24, 2017
plot confidence intervals for linear model with ggplot using geom_smooth
View CI_lm_ggplot.R
#####################################################
# CI-s for linear model with ggplot
#####################################################
library(ggplot2)
# -------------------------------------
# Use simulated data from Mick Wu
# -------------------------------------
set.seed(1)
View drunkwalks.R
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 Aug 29, 2017
closest geodesic distance with doParallel and foreach - example
View closest_geodesic_distance_parallel_foreach_example.R
# 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
View Euclidean_buffer_distortions.R
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 Apr 12, 2018
Geodesic buffer for point data
View make_GeodesicBuffer.R
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 Apr 8, 2017
Read <table> HTML tag with {XML} library
View XML_read_tbl.R
# 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 Apr 9, 2017
Read <table> HTML tag with {rvest} using CSS selectors
View rvest_read_tbl.R
# 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 Apr 8, 2017
Read <div> HTML tag with {rvest} using CSS selector
View rvest_Read_div.R
# 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"