Giter Club home page Giter Club logo

sfx's Introduction

Extra ‘sf’ Simple Features manipulations

CRAN Lifecycle: experimental License

Still a work-in-progress – not all features are available or behave properly (i.e. st_density(return_geometry = "raster")).

See the Reference section for detailed examples.

library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.3, PROJ 7.2.1; sf_use_s2() is TRUE
library(sfx)
library(ggplot2)
library(stars) # for geom_stars() 
## Loading required package: abind

olinda1 <- sf::read_sf(system.file("shape/olinda1.shp", package = "sf"))

olinda1_centroids <- olinda1  %>%
    sf::st_centroid()
## Warning in st_centroid.sf(.): st_centroid assumes attributes are constant over
## geometries of x

Point

# MASS::kde2d kernel (default)
olinda1_centroids %>%
    st_density() %>%
    ggplot() +
    geom_sf(data = olinda1, fill = NA, color = "gray80") +
    geom_sf(aes(color = density)) +
    scale_color_viridis_c() +
    theme_void()
## No bandwidth provided, using estimate: 0.0266888491366906
## No bandwidth provided, using estimate: 0.0218299890189734

# KernSmooth::bkde2D kernel
olinda1_centroids %>%
    st_density(method = "bkde2D") %>%
    ggplot() +
    geom_sf(data = olinda1, fill = NA, color = "gray80") +
    geom_sf(aes(color = density)) +
    scale_color_viridis_c() +
    theme_void()
## No bandwidth provided, using estimate: 0.00440286131103809
## No bandwidth provided, using estimate: 0.00457288717649596

Isoband

olinda1_centroids %>%
    st_density(return_geometry = "isoband") %>%
    ggplot() +
    geom_sf(aes(fill = level), alpha = 1) +
    geom_sf(data = olinda1_centroids, color = "red", size = 2) +
    scale_fill_viridis_c()
## No bandwidth provided, using estimate: 0.0266888491366906
## No bandwidth provided, using estimate: 0.0218299890189734

Raster

# NOT WORKING AS EXPECTED
olinda1_centroids %>%
    st_density(return_geometry = "raster", n = 50) %>%
    # use lambda expr to place . inside geom_stars
    # or else ggplot() will error on fortify() attempt
    {
      ggplot() +
        geom_stars(data = .) +
        coord_equal() +
        theme_void() +
        scale_fill_viridis_c() +
        scale_x_discrete(expand = c(0, 0)) +
        scale_y_discrete(expand = c(0, 0))
    }
## No bandwidth provided, using estimate: 0.0266888491366906
## No bandwidth provided, using estimate: 0.0218299890189734

Current Functions

# Density estimation (kernel based)
st_density

# Convert logical matrix to logical vector
st_any

# Binary logical helpers
st_any_contains
st_any_contains_properly
st_any_covered_by
st_any_covers
st_any_crosses
st_any_disjoint
st_any_equals
st_any_equals_exact
st_any_intersects
st_any_is_within_distance
st_any_overlaps
st_any_touches
st_any_within

# Joins
st_inner_join
st_left_join
st_anti_join
st_semi_join

# Unitless dimensions
st_ul_area
st_ul_distance
st_ul_length

# Bounding-box helpers
st_extent
st_xdist
st_ydist
st_xlim
st_ylim

Future Functions?

geom_sf_density()
plot_sf_density()

sfx's People

Contributors

seasmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sfx's Issues

Dont working the installation

Hi,

I wonder when I could to install this library, right now is not available in the CRAN.

Best regards,
Fabio Castro

Possible return types

Status Type
✔️ point
✔️ grid (regularly spaced point grid)
raster (polygons only; stars/raster maybe)
✔️ isoband/polygon
isoline/contour/line

Incorporate compute_expansion()

Currently compute_expansion() is a placeholder function to remove expansion computation from compute_limits(), and currently commented out.

Set dimensions of density grid

Setting dimensions of the density grid would allow contour lines to form a closed-loop rather than be truncated (applies to isoband and isoline).

Similar issue occurs in ggplot2 but is mitigated with scale_y/x_continuous(limits = c(m, n)).

# i.e.
x %>%
  st_density(x_expansion = 0.02, y_expansion = 0.02)

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.