Comments (9)
The idea is brilliant! That very much fits the scope of the scaling around focal points ...
Do you want to implement it here in landacapetools? That would be a great addition.
from landscapetools.
I think we should stick to viridis as a default - rcartocolor or colorbrewer are good for ~12 categories, but they are not the best for more...
There should be an option to modify the default colors though...
from landscapetools.
I think this is a great idea because it includes different scales, which is always a good idea. Maybe it would be also interesting to not "only" include the share of each class, but different metrics.
@marcosci we discussed something similar at least as a vignette, right?
from landscapetools.
@mhesselbarth @marcosci please take a look at the code below. I think the code make sense, but there is still a work to be done related to the plot style (@marcosci ?).
After we decided on this and make it a part of the package, I will start working on something similar, but for landscape metrics.
library(landscapemetrics)
library(landscapetools)
library(raster)
#> Loading required package: sp
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.3.2, PROJ 4.9.3
# new functions -----------------------------------------------------------
# calculates shares for one buffer, but many points
share = function(buffer, x, y){
df = as.data.frame(raster::extract(x = x, y = y, buffer = buffer, df = TRUE))
df = as.data.frame(table(df))
df$buffer = buffer
names(df) = c("id", "layer", "freq", "buffer")
df
}
# calculates shares for many buffers and many points
extract_multibuffer = function(x, y, width, cutoff){
buffers = seq(width, cutoff, width)
df = do.call(rbind, lapply(buffers, share, x, y))
}
# prepare example data ----------------------------------------------------
data("augusta_nlcd")
augusta_nlcd2 = raster(augusta_nlcd)
augusta_nlcd2[] = augusta_nlcd[]
new_point = st_sf(geom = st_sfc(
st_point(c(1265000, 1250000)),
st_point(c(1255000, 1257000))))
plot(augusta_nlcd2)
plot(new_point, add = TRUE)
# example calculations ----------------------------------------------------
result = extract_multibuffer(augusta_nlcd2, new_point, width = 5000, cutoff = 50000)
# final plot --------------------------------------------------------------
library(ggplot2)
ggplot(result, aes(buffer, freq, group = layer, fill = layer)) +
geom_area(position = "fill") +
facet_wrap(~id) +
expand_limits() +
scale_y_continuous(name = NULL, expand = c(0, 0), labels = scales::percent) +
scale_x_continuous(expand = c(0, 0)) +
xlab("Distance (km)")
Created on 2019-03-02 by the reprex package (v0.2.1)
from landscapetools.
I just had a look at it - awesome. Looks solid, pretty nifty @Nowosad !
Do you want to keep the colors? We had pretty much viridis/cividis for everything else, which isn't that nice in categorical case. Maybe you have a better idea? Something from rcartocolor maybe.
from landscapetools.
The option would be just adding a new scale_fill, or?
from landscapetools.
I implemented the function now (https://github.com/ropensci/landscapetools/blob/master/R/show_shareplot.R), if there is something that can be improved let me know.
from landscapetools.
Neat! Thanks @marcosci
# remotes::install_github("ropensci/landscapetools")
library(landscapemetrics)
library(landscapetools)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.3.2, PROJ 4.9.3
library(raster)
#> Loading required package: sp
data("augusta_nlcd")
augusta_nlcd2 = raster(augusta_nlcd)
augusta_nlcd2[] = augusta_nlcd[]
nlcd_colors = data.frame(levels = c(0L, 11L, 12L, 21L, 22L, 23L, 24L, 31L, 41L, 42L, 43L, 51L, 52L, 71L, 72L, 73L, 74L, 81L, 82L, 90L, 95L),
labels = c("nodata", "Open Water", "Perennial Ice/Snow", "Developed, Open Space",
"Developed, Low Intensity", "Developed, Medium Intensity", "Developed, High Intensity",
"Barren Land (Rock/Sand/Clay)", "Deciduous Forest", "Evergreen Forest",
"Mixed Forest", "Dwarf Scrub", "Shrub/Scrub", "Grassland/Herbaceous",
"Sedge/Herbaceous", "Lichens", "Moss", "Pasture/Hay", "Cultivated Crops",
"Woody Wetlands", "Emergent Herbaceous Wetlands"),
colors = c("#000000", "#476BA0", "#D1DDF9", "#DDC9C9", "#D89382", "#ED0000", "#AA0000",
"#B2ADA3", "#68AA63", "#1C6330", "#B5C98E", "#A58C30", "#CCBA7C",
"#E2E2C1", "#C9C977", "#99C147", "#77AD93", "#DBD83D", "#AA7028",
"#BAD8EA", "#70A3BA"),
stringsAsFactors = FALSE)
nlcd_colors = subset(nlcd_colors, levels %in% unique(augusta_nlcd2))
new_points = st_sf(geom = st_sfc(
st_point(c(1265000, 1250000)),
st_point(c(1255000, 1257000))))
show_shareplot(augusta_nlcd2, new_points, buffer_width = 5000, max_width = 50000) +
ggplot2::scale_fill_manual(values = nlcd_colors$colors)
#> Scale for 'fill' is already present. Adding another scale for 'fill',
#> which will replace the existing scale.
Created on 2019-04-29 by the reprex package (v0.2.1)
from landscapetools.
Looks good! 👍
from landscapetools.
Related Issues (20)
- util_facetplot color scales HOT 1
- landscapetools 0.5 HOT 16
- Generate neutral landscapes that match exactly the extent (non-NA cells) of another raster HOT 10
- Issues with `show_landscape()` for categorical rasters HOT 4
- long - wide option for raster2tibble HOT 1
- Build failure HOT 4
- Wrong result while using weighting in the util_classify function HOT 7
- show_landscape coloring bug with ratified raster
- CRAN HOT 2
- show_shareplot function cannot be found HOT 2
- How to define the order of the rasters shown with `show_landscape()`? HOT 3
- Support for terra HOT 9
- `util_extract_multibuffer` as a separate function HOT 10
- Re-add continuous integration workflows? HOT 5
- Fix pkgdown configuration for reference HOT 2
- random % with corresponding % from real landscape HOT 8
- Discrepancy in the `util_classify()` docs HOT 1
- white space
- util_facetplot + raster names
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from landscapetools.