Skip to content

Instantly share code, notes, and snippets.

Avatar

Timothée Giraud rCarto

View GitHub Profile
View Paris.R
library(sf)
library(spatstat)
library(sp)
library(maptools)
library(raster)
library(cartography)
library(SpatialPosition)
## import dataset
feat <- sf::st_read("https://gist.githubusercontent.com/rCarto/747164575e3f216a123c3092d0ce9162/raw/f12390464f255b5f9760c577ab6bf5456cf61a40/iris75.geojson")
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 mtq.R
library(raster)
library(cartography)
library(sf)
library(SpatialPosition)
mtq <- st_read(system.file("shape/martinique.shp", package="cartography"))
# use WGS84 proj
mtq_latlon <- st_transform(mtq, 4326)
# this call throw an error but seems to work...
getData('SRTM', lon=-61, lat=14)
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)
@rCarto
rCarto / cartomix.R
Last active May 15, 2019
Script to build the cartomix figure
View cartomix.R
library(cartography)
library(sp)
library(sf)
# Load data
data(nuts2006)
# Save image
sizes <- getFigDim(x = nuts0.spdf, width = 700, mar = c(0,0,0,0), res = 100)
png('./img/map8.png', width = sizes[1], height = sizes[2], res = 100)
You can’t perform that action at this time.