marcosci / layer Goto Github PK
View Code? Open in Web Editor NEWCreate stacked tilted maps
Home Page: https://marcosci.github.io/layer/
License: Creative Commons Zero v1.0 Universal
Create stacked tilted maps
Home Page: https://marcosci.github.io/layer/
License: Creative Commons Zero v1.0 Universal
First of all, good job creating this package. I am trying to plot 2 raster files but when I am using the plot_tiltedmaps
function the plot is empty. I am following the steps in the 2nd tutorial, called More advanced example. Any ideas why is that?
Here is the code:
library(layer)
library(terra)
wd <- "path/"
pop = rast(paste0(wd, "pop.tif"))
agbh = rast(paste0(wd, "agbh.tif"))
pop <- tilt_map(pop, y_tilt = 3, x_shift = 25, y_shift = 50, parallel = TRUE)
agbh <- tilt_map(agbh, y_tilt = 3, x_shift = 50, y_shift = 100, parallel = TRUE)
map_list <- list(pop, agbh)
plot_tiltedmaps(map_list, palette = c("tofino", "rocket"), direction = c(-1, 1))
You can download the data from here.
tilt_map is currently reasonably fast, but applied to large raster ( > 5000x5000 cells) it is kind of a bottleneck.
We could simply wrap the last line of the function where we apply the shear and rotate matrix in a future_map or similar.
Will be implemented, as soon as someone needs this.
This is a super cool project, and something that I've always wanted to see in rstats. Thank you for thinking of this!
Take the following with a grain of salt and only if you are inspired by it, or see it as useful. Otherwise, feel free to close the issue.
I'm wondering how difficult it would be to implement a feature to link points or polygon centroids to the underlying raster? Something like the following, but with lines for all points:
Hi,
I am having a hard time testing and understanding what does it mean to stretch and tilt a map with tilt_map
. Therefore I suggest there is a little more explanation on what each parameter of the function mean and maybe a few more examples. How much they vary, within which ranges? What is the meaning of a higher or lower value for each parameter? What is the reference if I want a map which is not rotated/tilted/shifted?
I came to this suggestion because I am trying to plot a series of maps, but with no rotation/tilting, I want to keep maps just as they are (ploting as if I did plot(x)
) but still plot a pile of them, one in front of another. How can I do it?
Hi all. Thanks for such a handy package!
I'm trying to use it with data from the geobr
package, but I'm getting the following error:
library(layer)
library(sf)
library(ggplot2)
library(geobr)
landscape_1 <- geobr::read_state()
tilt_landscape_1 <- tilt_map(landscape_1)
Error in
[[<-.data.frame
(*tmp*
, i, value = numeric(0)) :
replacement has 0 rows, data has 27
It works fine with a simple ggplot ggplot() + geom_sf(data=landscape_1, color='gray') + theme_void()
Hello @marcosci -
Apologies if this is a silly question, but I cannot figure out how to make this work.
I am working with cleaned tidycensus
data that looks like this:
# A tibble: 99 x 16
GEOID NAME urban_name pct_units_loan pct_units_owned pct_units_rented pct_asian pct_black pct_hispanic pct_white
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 32003~ Cens~ Paradise 59.5 17.2 23.3 4.05 4.57 34.2 67.8
2 32003~ Cens~ Paradise 11.3 5.94 82.8 7.45 13.0 38.2 62.1
3 32003~ Cens~ Paradise 8.00 7.88 84.1 15.8 26.1 29.3 36.0
4 32003~ Cens~ Paradise 9.24 3.31 87.4 19.7 22.6 18.1 48.4
5 32003~ Cens~ Paradise 33.0 11.2 55.7 20.0 8.72 10.4 59.9
6 32003~ Cens~ Paradise 27.5 14.5 58.0 5.21 5.54 63.1 73.4
7 32003~ Cens~ Paradise 5.28 1.82 92.9 16.7 8.79 50.3 42.5
8 32003~ Cens~ Paradise 42.2 11.9 45.9 5.67 6.80 54.3 68.2
9 32003~ Cens~ Paradise 6.46 18.1 75.5 13.4 1.46 6.91 77.8
10 32003~ Cens~ Paradise 35.4 14.6 50 0.377 8.75 64.2 47.6
# ... with 89 more rows, and 6 more variables: pct_rent.ratio <dbl>, pct_mortgage.ratioE <dbl>,
# pct_graduate.degree <dbl>, geometry <POLYGON [°]>, id <chr>, distance.to.stadium <dbl>
And, specifically, the geometry
data looks like this:
geometry
<POLYGON [°]>
1 ((-115.101 36.10003, -115.0918 36.10017, -115.0915 36.09321, -115.0913 36.08562, -115.101...
2 ((-115.1374 36.10775, -115.1328 36.10765, -115.1282 36.10752, -115.1253 36.10746, -115.12...
3 ((-115.2165 36.11129, -115.2164 36.11504, -115.208 36.11553, -115.208 36.11179, -115.208 ...
4 ((-115.2166 36.08949, -115.2165 36.09313, -115.2122 36.09333, -115.2079 36.09359, -115.20...
5 ((-115.1723 36.01738, -115.1723 36.02469, -115.1634 36.02458, -115.1546 36.02413, -115.15...
6 ((-115.1369 36.13699, -115.129 36.13673, -115.1283 36.13688, -115.1276 36.13703, -115.123...
7 ((-115.1379 36.11465, -115.1332 36.11466, -115.1313 36.11467, -115.1286 36.11469, -115.12...
8 ((-115.1324 36.09726, -115.1279 36.09721, -115.1189 36.09651, -115.1189 36.09305, -115.11...
9 ((-115.1808 36.12621, -115.1804 36.1262, -115.1779 36.12606, -115.1678 36.12524, -115.167...
10 ((-115.0735 36.10762, -115.0674 36.10759, -115.0643 36.10758, -115.0639 36.10023, -115.07...
# ... with 89 more rows
The following ggplot
produces the map below ...
map1 <- ggplot(data = paradise.nevada, aes(fill = pct_units_rented)) +
geom_sf() +
theme_void() +
theme(legend.position = "none")
This is where I'm running into issues trying to figure out how to make this work.
I am attempting to do the following:
tilt_map1 <- tilt_map(map1)
But it creates the following error:
Error in mapply(create_dimension, values = d, is_raster = cell_midpoints, :
zero-length inputs cannot be mixed with those of non-zero length
Any advice on how to use layers
with ggplot and/or tidycensus would be greatly appreciated!
Neat package!
This is the classic "What is GIS?" stacked map figure, so it's great to see a packaged solution.
In the past, I have sheared grids and polygons to achieve a similar result.
In some of your examples, I find the rasters really clear, but features (like the wildfire below) hard to compare to other layers.
This is similar to #1, but I was thinking instead of lines connecting down, it might help to show the shared boundaries?
Eg. taking the example in the README (I couldn't find the data for the wildfire example)
library(layer)
tilt_landscape_1 <- tilt_map(landscape_1)
tilt_landscape_2 <- tilt_map(landscape_2, x_shift = 25, y_shift = 50)
tilt_landscape_3 <- tilt_map(landscape_3, x_shift = 50, y_shift = 100)
tilt_landscape_points <- tilt_map(landscape_points, x_shift = 75, y_shift = 150)
map_list <- list(tilt_landscape_1, tilt_landscape_2, tilt_landscape_3, tilt_landscape_points)
plot_tiltedmaps(map_list,
layer = c("value", "value", "value", NA),
palette = c("bilbao", "mako", "rocket", NA),
color = "grey40")
Here's a rough DIY solution, where I just bind the bbox (cast as a linestring to avoid it being filled, harder to tweak a polygon I think since the ggplot'ing happens within the function).
library(layer)
library(sf)
tilt_landscape_1 <- tilt_map(landscape_1)
tilt_landscape_2 <- tilt_map(landscape_2, x_shift = 25, y_shift = 50)
tilt_landscape_3 <- tilt_map(landscape_3, x_shift = 50, y_shift = 100)
landscape_with_bbox <- rbind(
landscape_points,
st_cast(st_as_sfc(st_bbox(landscape_points)), 'LINESTRING')
)
tilt_landscape_with_bbox <- tilt_map(landscape_with_bbox, x_shift = 75, y_shift = 150)
map_list_with_bbox <- list(tilt_landscape_1, tilt_landscape_2, tilt_landscape_3, tilt_landscape_with_bbox)
plot_tiltedmaps(map_list_with_bbox,
layer = c("value", "value", "value", NA),
palette = c("bilbao", "mako", "rocket", NA),
color = c("grey40", "grey40", "grey40", "black"))
Maybe a broader solution for the package would be adding a toggle to plot_tiltedmaps()
to add a boundary to all the layers?
Thank you!
Might be a good idea to add handling of raster stacks which would remove the need to run the tilt_map()
function and to (mis)specify the arguments for each raster?
A proposed solution would be a tilt_stack()
function where users specify the usual arguments but those are then applied to all landscapes (e.g. y_shift = 30
would mean a sequence of 0, 30, 60, 90etc as shift values for each raster).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.