-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
142 lines (118 loc) · 3.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
output: github_document
---
# Extra 'sf' Simple Features manipulations
[![CRAN](http://www.r-pkg.org/badges/version/sfx)](https://cran.r-project.org/package=sfx)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-red.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![License](http://img.shields.io/badge/license-GPL%20%28%3E=%202%29-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html)
Still a work-in-progress -- I want to add a few more features, such as:
* Random density points (random points with density values? why? guassian distribution for sampling?)
* Alternative density methods.
See the [Reference section][ref_sec] for detailed examples.
[ref_sec]: http://seasmith.github.io/packages/sfx/reference/index.html
```{r, collapse=TRUE}
library(sf)
library(sfx)
library(ggplot2)
library(stars) # for geom_stars()
olinda1 <- sf::read_sf(system.file("shape/olinda1.shp", package = "sf"))
olinda1_centroids <- olinda1 %>%
sf::st_centroid()
```
## Point
```{r}
# 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()
# 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()
```
## Grid
```{r}
# n = 10 produces a 10x10 grid
olinda1_centroids %>%
st_density(return_geometry = "grid", n = 10) %>%
ggplot() +
geom_sf(data = olinda1, fill = NA, color = "gray80") +
geom_sf(aes(color = density)) +
scale_color_viridis_c() +
theme_void()
```
## Isoband
```{r}
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()
```
## Raster
```{r, eval=TRUE}
# 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))
}
```
## Current Functions
```{r, eval=FALSE}
# Density estimation (kernel based)
st_density
# Joins
st_inner_join
st_left_join
st_anti_join
st_semi_join
# 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
# 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?
```{r, eval=FALSE}
geom_sf_density()
plot_sf_density()
```