Skip to content

Instantly share code, notes, and snippets.

Avatar

Timothée Giraud rCarto

View GitHub Profile
View plot.R
library(sf)
nc = st_read(system.file("shape/nc.shp", package="sf"))
nc <- st_transform(nc, 32119)
# regular grid 512096 polygons
grid <- st_make_grid(x = nc, cellsize = 500)
t0 <- Sys.time()
plot(st_geometry(nc))
plot(grid, add = TRUE)
# end of the second plot
View mapbox.md
library(cartography)
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0

# create an sf object centered on Tizi Ouzou city
tizi <- data.frame(name = "Tizi Ouzou", longitude = 4.06, latitude = 36.71)
tizi <- st_as_sf(tizi, coords = c("longitude", "latitude"), crs = 4326)
tizi <- st_transform(tizi, 3857)
tizi <- st_buffer(tizi, 5000)
View interactiveposition.R
library(cartography)
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg",
package="cartography"))
bks <- getBreaks(v = mtq$MED, nclass = 5,
method = "quantile")
cols <- carto.pal(pal1 = "turquoise.pal", n1 = 5)
choroLayer(x = mtq, var = "MED",
breaks = bks, col = cols,
View localpeaks.R
library(SpatialPosition)
library(raster)
data(hospital)
# Compute Stewart potentials from known points (hospital) on a
# grid defined by its resolution
pot <- stewart(knownpts = hospital, varname = "capacity",
typefct = "exponential", span = 750, beta = 3,
resolution = 100, mask = paris)
# Create a raster of potentials values
ras <- rasterStewart(x = pot)
View carto_facet.R
# World basemap
download.file(url = "https://raw.githubusercontent.com/riatelab/basemaps/master/World/countries.geojson",
destfile = "country.geojson")
# Graticules layer
download.file(url = "https://raw.githubusercontent.com/riatelab/basemaps/master/World/graticule30.geojson",
destfile = "graticule.geojson")
# Population data base
download.file(url = "https://population.un.org/wup/Download/Files/WUP2018-F12-Cities_Over_300K.xls",
destfile = "citypop.xls")
View disc2019.R
library(cartography)
library(sp)
# Load data
data(nuts2006)
# Get a SpatialLinesDataFrame of countries borders
nuts0.contig.spdf <- getBorders(nuts0.spdf)
# Get the GDP per capita
nuts0.df$gdpcap <- nuts0.df$gdppps2008/nuts0.df$pop2008*1000000
View pencil2019.R
library(sf)
library(cartography)
library(png)
# import background image
if (!file.exists("img/background.png")) {
githubURL <- "https://raw.githubusercontent.com/gadenbuie/ggpomological/master/inst/images/pomological_background.png"
download.file(githubURL, "img/background.png")
}
img <- readPNG("img/background.png")
# import Communes of Martinique (sf dataframe within cartography package)
View roads.R
library(sf)
library(cartography)
library(osrm)
# set osrm to my own server
options(osrm.server = "http://address.of.my.server/", osrm.profile = "driving")
# destination point (useR2019 conference in Toulouse)
dst <- data.frame(id="dst", x = 1.4344, y = 43.6113)
dst <- st_as_sf(dst, coords = c('x','y'), crs = 4326)
View popcircle.R
library(rnaturalearth)
library(sf)
library(wbstats)
library(popcircle)
library(cartography)
# Get countries
ctry <- ne_countries(scale = 50, returnclass = "sf")
ctry <- st_transform(ctry, 54030)
View tanakapop.R
library(raster)
library(sf)
library(viridis)
library(cartography)
library(tanaka)
temp <- tempfile()
data_url <- "http://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_GPW4_GLOBE_R2015A/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k/V1-0/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.zip"
download.file(data_url, temp)
unzip(temp, exdir = "pop")
You can’t perform that action at this time.