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 / Confidence bands & legend - ggplot.R
Last active January 21, 2017 19:30
Confidence bands & set order in legend - ggplot
# ======================================================================================
# Confidence bands and setting order of line types in legend - ggplot
# ======================================================================================
library(ggplot2)
# ========== create some data
my.data <- data.frame(time = rep(1:10,2),
means = 2:21,
lowerCI = 1:20,
@valentinitnelav
valentinitnelav / Confidence lines & legend - ggplot.R
Last active January 21, 2017 19:30
Confidence lines & set order in legend - ggplot
# ======================================================================================
# Manually add confidence lines and setting order of line types in legend - ggplot
# The lower and upper values could be computed through bootstrapping.
# ======================================================================================
library(ggplot2)
# create some data
my.data <- data.frame(time = rep(1:10, 2),
means = 2:21,
@valentinitnelav
valentinitnelav / IslandAssembly_todolist.md
Created January 10, 2017 16:40 — forked from dylancraven/IslandAssembly_todolist.md
To-do list for Island forest assembly project
  • 1) Environmental data: MAT, MAP, Temp Seasonality, Precip Seasonality, Elevation, PET
  • 2) Distances between plots (Priority Level 1)
  • 3) Area + Perimeter of islands (P/A ratio) (Priority Level 3)
  • 4) Anthropogenic disturbance (road density, change in land cover, human population density) (Priority Level 2)
  • 5) Isolation metrics for islands (Priority Level 3)
  • 6) Hawaii only: substrate age (Priority Level 1)
@valentinitnelav
valentinitnelav / Pacific centered world map with ggplot.R
Last active July 12, 2023 08:25
Pacific centered world map with ggplot (change central/prime meridian)
# ======================================================================================
# Pacific centered world map with ggplot
# Enhanced aspect with graticules and labels
# The central/prime meridian can be shifted with any positive value towards west
# Can use any project of known PROJ.4 string
# ======================================================================================
# ~~~~~~~~~~~ Load needed libraries ~~~~~~~~~~~ #
library(data.table)
library(ggplot2)
@valentinitnelav
valentinitnelav / Shift central meridian - test, Greenland example.R
Last active January 1, 2017 12:29
Shift central meridian - fails concave polygon & closure of split polygons, Greenland example.R
# ===================================================================================
# Test case - Shift central/prime meridian
# Fails concave polygons and closure of split polygons
# Show case example for Greenland
# ===================================================================================
# __________ Load needed libraries __________ #
library(data.table)
library(ggplot2)
library(maps)
@valentinitnelav
valentinitnelav / Shift central meridian - fails on Antarctica.R
Last active January 1, 2017 12:38
Shift central meridian - fails on Antarctica
# ===================================================================================
# Shift central/prime meridian (data.table + ggplot)
# Inspired from the answer of Joris Meys given here:
# http://stackoverflow.com/questions/5353184/fixing-maps-library-data-for-pacific-centred-0-360-longitude-display
# and the code of Claudia Engel at: https://gist.github.com/cengel/2165374#file-greatcircleflights-r
# or at: http://web.stanford.edu/~cengel/cgi-bin/anthrospace/great-circles-on-a-recentered-worldmap-in-ggplot
#
# NOTE: Fails to properly display Antarctica
# (extra points need to be added in order to properly close the polygons at -90 dg)
# Check a different solution here: https://gist.github.com/valentinitnelav/b4d76cd9e84414ac4d1ac48d64615784
@valentinitnelav
valentinitnelav / Shift central (prime) meridian.R
Last active January 1, 2017 10:53
Shift central/prime meridian by splitting the world map in two
# ===================================================================================
# Shift central/prime meridian and plot world map with ggplot
# ===================================================================================
# __________ Load needed libraries __________ #
library(data.table)
library(ggplot2)
library(rgdal)
library(rgeos)
library(maps)
# define the function:
Interaction.Plots_fun <- function(MyMatrix.lst, data.lst) {
# storing default par() for reverting par to original/default values
par.default <- par()
# on.exit(par(par.default)) # when exiting function par(), restore to default (? - need to test!)
# par(par.default) # or simply call each time this line
# open a pdf device with desired parameters
pdf(file=paste0("Mueller ", format(Sys.time(), "%Y-%m-%d %H-%M-%p"), ".pdf"), onefile=TRUE, width=24, height=8.27)
# remember that an A4 is 8.27 × 11.69 in. Here you want a landscape format width > height!
# =============================================================================================================
# Scraps the TPL web page for all families of angiosperms and downloads the corresponding *csv files.
# Then grabs the unique species names from this pile of data and builds a custom dictionary for a spell checker.
# =============================================================================================================
# _________ Read the family names from the TPL web page (Angiosperms only) _________ #
# I adapted code from http://www.stat.berkeley.edu/~spector/s133/Readexample.html for parsing through web pages
thepage <- readLines("http://www.theplantlist.org/1.1/browse/A/")
# One can notice that family names are in rows of such patern:
# <i class=\"family\">Piperaceae</i></a>"
# ======================================================================================
# Create a simple world map in Eckert IV projection with labeled graticules using ggplot.
# Repel overlapping text labels with ggrepel.
# Eckert IV is a nice looking equal-area projection :)
# https://upload.wikimedia.org/wikipedia/commons/c/c5/Ecker_IV_projection_SW.jpg
# ======================================================================================
# Set a working directory with setwd() or work with an RStudio project
# ~~~~~~~~~~~ Set libraries ~~~~~~~~~~~ #