-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-variable / multivariate specification functions #819
Comments
Thx. It's already some time ago that I've worked on stars objects with bands and attributes. So I have to recall which function calls should be supported and that the 'correct' approach is. At least, tmap4 does the 'multivariate' stuff via Since tm_shape(L7) +
tm_raster(col = tm_mv_dim("band", c(3, 2, 1)), col.scale = tm_scale_rgb()) Or, shorter: tm_shape(L7) +
tm_rgb(tm_mv_dim("band", c(3, 2, 1))) Have to make sure your code works as well (backwards compatibility) or at least throws some useful errors. Do you know if this code worked in earlier tmap4 development versions? |
FYI: This works as well L7split = split(L7)
tm_shape(L7split) +
tm_rgb(tm_mv("X3", "X2", "X1")) but |
See the newly added examples of
Let me now how useful this is. |
@mtennekes would it be possible to merge |
That's not so easy, because in general, the value specified for a visual variable (say
For That is the history behind these functions and their names. Suggestion to make this more intuitive (while still possible to implement) are welcome. |
@mtennekes, what do you think about updating the names:
? |
I like those names @Nowosad before we need to make sure to cover all use cases. Not just raster objects, but also vector objects. For instance, the function Currently this family of functions is: 1 Examples of vector shapes: tm_shape(World) +
tm_polygons(tm_mv("HPI", "well_being"))
tm_shape(World) +
tm_polygons(tm_shape_vars(n = 3))
tm_shape(World) +
tm_polygons(tm_mv_shape_vars(ids = c(4, 9))) So what would be the most intuitive names? We could also combine 1 Then, |
Ignore my previous post. I've managed to make it into one function: @Nowosad @marine-ecologist Please check this script https://github.com/r-tmap/tmap/blob/master/sandbox/vv2.R, which we should convert to vignette(s).
This has breaking changes w.r.t. the earlier v4 implementation of multivariate visual variables. E.g. tm_shape(World) +
tm_polygons(tm_mv("HPI", "well_being")) will become tm_shape(World) +
tm_polygons(tm_vars(c("HPI", "well_being"))) |
Awesome! I think that this is much more intuitive. I checked the script, and have a few comments (reprex attached below):
library(tmap)
file = system.file("tif/L7_ETMs.tif", package = "stars")
# 1 complex stars ???
# 2 -- spurious warning
L7_terra = terra::rast(file)
tm_shape(L7_terra) +
tm_rgb(tm_vars(dimvalues = 1:3, multivariate = TRUE))
#> Warning in apply_scale(s, l, crt, val, unm, nm__ord, "legnr", "crtnr", sortRev,
#> : Too many variables defined
# 3 error
library(tmap.glyphs)
tm_shape(NLD_prov) +
tm_polygons() +
tm_donuts(parts = tm_vars(c("origin_native", "origin_west", "origin_non_west"), multivariate = TRUE),
size = "population",
size.scale = tm_scale_continuous(values.scale = 1),
fill.scale = tm_scale_categorical(values = "brewer.dark2"))
#> Error in get(fun, mode = "function", envir = envir): object 'tmapScaleComposition' of mode 'function' was not found |
Thx @Nowosad
Actually, it is as expected, just to show the multiple ways to Rome. Maybe it would be better to ignore the output, and show multiple tmap code chunks that produce the same map.
Fixed. The problem was in the tmap code: terra doesn't use dimensions, so dimvalues are ignored. By default all (in this case 6) variables are shown. Perhaps the warning could be a little more helpful.
Fixed! (please reinstall tmap.glyphs with the latest gh version) |
Hi @mtennekes -- just to let you know, I am still getting warnings/errors after updating the packages from GitHub, see: # remotes::install_github("r-tmap/tmap")
# remotes::install_github("r-tmap/tmap.glyphs")
library(tmap)
file = system.file("tif/L7_ETMs.tif", package = "stars")
# 1 -- spurious warning
L7_terra = terra::rast(file)
tm_shape(L7_terra) +
tm_rgb(tm_vars(dimvalues = 1:3, multivariate = TRUE))
#> Warning in apply_scale(s, l, crt, val, unm, nm__ord, "legnr", "crtnr", sortRev,
#> : Too many variables defined # 2 -- glyphs
library(tmap.glyphs)
tm_shape(NLD_prov) +
tm_polygons() +
tm_donuts(parts = tm_vars(c("origin_native", "origin_west", "origin_non_west"), multivariate = TRUE),
size = "population",
size.scale = tm_scale_continuous(values.scale = 1),
fill.scale = tm_scale_categorical(values = "brewer.dark2"))
#> Error in get_scale_defaults(scale, o, aes, layer, cls, ct): could not find function "get_scale_defaults" |
Should be fixed. Please check if the error message for (1) is clear and if (2) works @Nowosad |
Thanks, @mtennekes -- the first example is fixed, but the second one still have some issues: # remotes::install_github("r-tmap/tmap")
# remotes::install_github("r-tmap/tmap.glyphs")
library(tmap)
file = system.file("tif/L7_ETMs.tif", package = "stars")
# glyphs
library(tmap.glyphs)
tm_shape(NLD_prov) +
tm_polygons() +
tm_donuts(parts = tm_vars(c("origin_native", "origin_west", "origin_non_west"), multivariate = TRUE),
size = "population",
size.scale = tm_scale_continuous(values.scale = 1),
fill.scale = tm_scale_categorical(values = "brewer.dark2"))
#> Error in tmapValuesCVV_num(x = c(0, 1), value.na = NA, n = 3L, range = c(0, : could not find function "tmapValuesCVV_num" |
Ok, the second one should be working. I had to export a s***tload of internal functions to make it work. They are hidden from the documentation index. However, they mess up the autocompletion when typing |
Example using the stars raster:
The text was updated successfully, but these errors were encountered: