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 / XML_ReadListItems.R
Last active April 9, 2017 08:52
Read list items with {XML} using the XPath selector
# Load library
library(XML)
# -----------------------
# Read the web page
# -----------------------
link <- "http://www.adirondacklakessurvey.org/alscrpt.inc.php?alscpond=020225B&pname=ALLEGANY%20BROOK%20POND"
# NOTE: is ethical to store the page and not read it unnecessarily too many times,
# overloading their server
link.scrap <- htmlParse(link)
@valentinitnelav
valentinitnelav / rvest_ReadListItems.R
Last active March 26, 2017 19:49
Read list items with {rvest} using CSS or XPath selectors
# Load library
library(rvest)
# -----------------------
# Read the web page
# -----------------------
link <- "http://www.adirondacklakessurvey.org/alscrpt.inc.php?alscpond=020225B&pname=ALLEGANY%20BROOK%20POND"
# NOTE: is ethical to store the page and not read it unnecessarily too many times,
# overloading their server
link.scrap <- read_html(link)
@valentinitnelav
valentinitnelav / aggregate.R
Last active March 1, 2017 07:37
count species by lake combinations
# ================================
# helper script for species counts (lakes for Leana)
# ================================
library(data.table)
# read data
lake_data <- fread("links_extract_dt.csv")
# count unique species by combination of `Pond Name`, Town, County
# skip or add column in the "by" section if needed
@valentinitnelav
valentinitnelav / Read_from_URL_lake.R
Created February 22, 2017 09:42
Script to read list of lake links and parse through them (for Leana)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Script to read list of lake links and parse through them
# for Leana
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(XML)
library(stringr)
library(data.table)
#####################################################
#####################################################
@valentinitnelav
valentinitnelav / Plot inwards ticks - ggplot.R
Last active October 7, 2021 13:14
Plot with inwards ticks - ggplot
# ==========================================================================
# Example of plot for publication with inwards ticks in ggplot
# ==========================================================================
library(ggplot2)
# ==================================
# create some data
# ==================================
set.seed(1)
@valentinitnelav
valentinitnelav / Plot inwards ticks - base R.R
Created January 21, 2017 21:13
Plot with inwards ticks - base R
# ==========================================================================
# Example of plot for publication in base R with inwards ticks
# ==========================================================================
# ==================================
# create some data
# ==================================
set.seed(1)
DF <- data.frame(year = c(2000:2020),
mean = rnorm(n=21, mean=100, sd=10))
@valentinitnelav
valentinitnelav / dotplot for publication - ggplot.R
Last active January 14, 2018 02:44
Create a dotplot for publication - ggplot.R
# ==========================================================================
# 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
# ==================================
@valentinitnelav
valentinitnelav / barplot for publication - ggplot.R
Last active March 7, 2017 09:10
Create a barplot for publication - ggplot.R
# ==========================================================================
# Barplot with CI/error bars for publication - ggplot
# see more at: http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/
# ==========================================================================
library(ggplot2)
# ==================================
# create some data
# ==================================
@valentinitnelav
valentinitnelav / Confidence bands & legend, color - ggplot.R
Last active September 7, 2017 14:03
Colored confidence bands & set order in legend - ggplot
# ======================================================================================
# Color case.
# Confidence bands and setting order of line types in legend based on group - ggplot.
# The lower and upper values could be computed through bootstrapping.
# ======================================================================================
library(ggplot2)
# create some data
x=seq(from=0, to=2*pi, by=0.1)
@valentinitnelav
valentinitnelav / Confidence lines & legend, color - ggplot.R
Last active September 7, 2017 14:02
Colored confidence lines & set order in legend - ggplot
# ======================================================================================
# Color case.
# Confidence lines and setting order of line types in legend based on group - ggplot.
# ======================================================================================
library(ggplot2)
# create some data
x=seq(from=0, to=2*pi, by=0.1)
my.data <- data.frame(x = rep(x,2),