This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ====================================================================================== | |
# Create a simple world map in Robinson projection with labeled graticules using ggplot | |
# ====================================================================================== | |
# Set a working directory with setwd() or work with an RStudio project | |
# __________ Set libraries | |
library(rgdal) # for spTransform() & project() | |
library(ggplot2) # for ggplot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ====================================================================================== | |
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converting coordinates from DMS or DdM formats to decimal | |
# DMS = "degrees minutes seconds"; DdM = "degrees decimal minutes" | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
dg2dec <- function(varb, Dg=NA, Min=NA, Sec=NA, SW.Hemisphere="S|W") { | |
# Dg=decimal, Min=minutes and Sec=seconds; | |
# NOTE 1 - if the format is "degrees decimal minutes - DdM" (e.g. 40° 26.767′ N) and not | |
# "degrees minutes seconds - DMS" (e.g. 40° 26′ 46″ N), then call the function only with | |
# Dg and Min arguments, like dg2dec(varb, Dg="°", Min="′N"). | |
# Same applies when there is no seconds symbol (e.g. 45°12'7.38). | |
# Note that one should not use blank spaces in Dg, Min or Sec arguments (will return NA). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================================== | |
# Example of plot for publication with inwards ticks in ggplot | |
# ========================================================================== | |
library(ggplot2) | |
# ================================== | |
# create some data | |
# ================================== | |
set.seed(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract long-lat coordinates from a bunch of kmz files | |
# first unzips the KMZ-s then reads coordinates from each KML with getKMLcoordinates {maptools} | |
# (worth checking this as well: https://gist.github.com/holstius/6631918 ) | |
library(maptools) | |
# list the kmz files in a given folder path | |
KMZs <- list.files(path="Data/kmz-files", pattern="*.kmz", full.names=FALSE) | |
# unzip each KMZ file and read coordinates with getKMLcoordinates() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================================================================= | |
# 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>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================================== | |
# Dotplot with CI/error bars for publication - ggplot | |
# see also: http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/ | |
# ========================================================================== | |
library(ggplot2) | |
# ================================== | |
# create some data | |
# ================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# ------------------------------------- |
NewerOlder