Skip to content

Instantly share code, notes, and snippets.

View pierreroudier's full-sized avatar

Pierre Roudier pierreroudier

View GitHub Profile
@pierreroudier
pierreroudier / sample_raster.R
Created January 28, 2022 03:19
Sample raster
library(sp)
library(raster)
library(ggplot2)
# load example data
data("meuse.grid", package = "sp")
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE
@pierreroudier
pierreroudier / gist:96d07509f2f45dbafed393fb1da08d29
Created June 17, 2021 00:09
Example coordinate matrix from a `MULTILINE` object
coords <- structure(list(X = c(1821804.61206496, 1821804.53388462, 1821804.45241005,
1821804.37093547, 1821803.63766419, 1821803.06404773, 1821801.08230283,
1821799.67087991, 1821797.16404961, 1821795.58638206, 1821791.81131096,
1821790.27888289, 1821788.83451778, 1821787.47821557, 1821782.52296569,
1821780.66793137, 1821779.06061595, 1821775.68962231, 1821770.6783751,
1821769.31877881, 1821766.85059942, 1821765.23669656, 1821761.92741568,
1821760.40486898, 1821759.21481077, 1821756.92275687, 1821755.3220282,
1821753.54846811, 1821751.92468512, 1821750.53215511, 1821749.14621232,
1821744.7340796, 1821743.43290713, 1821741.17622498, 1821740.47502158,
1821738.71707379, 1821735.30241579, 1821733.5411775, 1821733.00292668,
@pierreroudier
pierreroudier / sf.R
Last active September 25, 2018 08:23 — forked from baptiste/sf.R
library(sf)
library(mapview)
sf::st_layers('zzz.gpx')
my_tracks_points <- sf::st_read('zzz.gpx', 'track_points')
my_tracks_line <- sf::st_read('zzz.gpx', 'tracks')
m1 <- mapview(my_tracks_line, map.types = "Esri.WorldImagery")
m2 <- mapview(my_tracks_points, zcol = 'ele', legend = TRUE)
@pierreroudier
pierreroudier / comparison-r2-ccc.R
Created November 15, 2017 22:01
Quick comparison R2-CCC
library(ggplot2)
library(dplyr)
# Creating dummy data
d <- data.frame(
x = rnorm(100,10,3)
) %>%
mutate(
y = jitter(x, factor = 800) - 5 * cos(x/10)
)
@pierreroudier
pierreroudier / df_to_sf.R
Last active October 18, 2017 06:08
Converting a data.frame into a (MULTIPOLYGON) sf object
library(sf)
library(dplyr)
# A function that closes the polygons if
# the first row of coordinates is different than
# the last rows of coordinates
add_first_row <- function(x) {
if (!identical(
as.numeric(x[1,]),
as.numeric(x[nrow(x),])

Keybase proof

I hereby claim:

  • I am pierreroudier on github.
  • I am pierreroudier (https://keybase.io/pierreroudier) on keybase.
  • I have a public key whose fingerprint is 4364 5A25 9729 B7B2 3E0E B585 923C 8CA0 4E71 2D37

To claim this, I am signing this object:

@pierreroudier
pierreroudier / varying-width-ggplot.r
Last active July 6, 2021 16:49
Varying line width with ggplot2
# First, let's make up some dummy data
# I assume your data is 3 columns: year, the x scale between 0 and 1, and some values
library(plyr)
df <- ldply(1995:2015, function(x) data.frame(year = x, x = seq(0,1, by = 0.1), values = rnorm(11)))
# You can check if my assumptions about your data are correct:
head(df)
# The plotting code begins here
@pierreroudier
pierreroudier / test_raster_ggplot2.R
Created December 2, 2011 00:56
Bug in geom_raster?
# I've been testing Hadley's last dev version of ggplot2 - my interest being mainly triggered
# by the new and shiny geom_raster(), as I'm still convinced a mapping framework based on
# ggplot2 would just be awesome to see (fast and easy production of very nice looking maps).
#
# Somehow I managed to test it using a simple coercition of the SpatialPixelsDataFrame objects
# into data.frames, but for some reasons it seems to be handling the coordinates on a weird way.
#
# Is that a bug?
#