Coder Social home page Coder Social logo

victor's Introduction

victor

Lifecycle: experimental

The goal of victor is to interact with the Mapbox Vector Tile API ( also here ) in R. Grab a vector tile(s), work with it using the simple features package sf. Plot static maps with ggplot2, tmap, etc.

Inspired and/or fuelled by:

Installation

Install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("adam-gruer/victor")

Mapbox Token

You will need a Mapbox Access Token to use their API. Once you have a token add a line to your .Renviron file

MAPBOX_API_KEY=your_acess_token

The easiest way to edit .Renviron is with the usethis pavkage usethis::edit_r_environ(). You will have to restart R after editing the file for the token to be available.

Example

Let’s create a map of Melburn and surrounding cities:

Use the spoils function to retrieve a tile for a given location and zoom It returns a list of simple features data frames. One for each layer of data provided by mapbox.

library(victor)
library(sf)
library(tidyverse)
melburn <- spoils(zoom = 7, longitude = 144.8430, latitude = -37.7311)

roads <- filter(melburn$road,!st_is(geometry, "POINT")) 
road_shields <-  filter(melburn$road,
                        st_is(geometry, "POINT"),
                        str_starts(ref, "M") ) %>% 
                  group_by(ref) %>% 
                  filter(row_number() == 1)
places <- filter(melburn$place_label, symbolrank < 11) %>% 
  mutate(name = case_when(name == "Melbourne" ~ "Melburn",
                          TRUE ~ as.character(name)))

ggplot() +
  geom_sf(data = melburn$water, fill = "lightblue") +
  geom_sf(aes(colour = class), data = roads) +
  geom_sf_label(aes(label = ref), data = road_shields) +
  
  geom_sf_label(aes(label = name, size = symbolrank),
                data = places) +
  scale_size(trans = "reverse", range = c(4,6)) +
  theme_void() +
  theme( panel.grid.major = element_line(size = 0),
         plot.background = element_rect(fill = "antiquewhite"),
         legend.position = "none") 

Melburn CBD , zoomed in

cbd <- spoils(zoom = 15, long = 144.958869, lat =-37.820318)

ggplot() + geom_sf(data = cbd$water, fill = "lightblue") +
  geom_sf(data = cbd$building, aes(fill = type )) +
  geom_sf(data = cbd$road) +
  geom_sf_label(data = cbd$natural_label,
                aes (label = name),
                alpha = 0.4,
                nudge_x = 0.002) +
  geom_sf_label(data = filter(cbd$poi_label, 
                              category_en == "Aquarium"), 
                aes(label = name),
                alpha = 0.4) +
    theme_void() +
  theme( panel.grid.major = element_line(size = 0),
         plot.background = element_rect(fill = "antiquewhite1")) 

victor's People

Contributors

adam-gruer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

victor's Issues

update readme and vignette

change order of layers in example
highlight spoils function with a comment and explain what it returns

summary function for vector tile class

return a tibble summary of layers.

  • by layer number of features

  • factor variables and their levels

  • possibly print a summary while also returning the tibble

  • identify duplicate values

find optimal package name and function names

victor and spoils were best i could do on a friday night
maybe vikta and some lawnmore references / hex sticker byut still not super happy.
maybe see how package functionality develops

other ideas

  • victa / vikta
  • tily
  • tilyr
  • static

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.