Skip to content
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

tm_mv not available? #922

Closed
r-poloni opened this issue Aug 26, 2024 · 2 comments
Closed

tm_mv not available? #922

r-poloni opened this issue Aug 26, 2024 · 2 comments

Comments

@r-poloni
Copy link

r-poloni commented Aug 26, 2024

Hi, I have a script from last year, that simply draws maps based on a raster layer and points. Last year I struggled a bit to write it with tmap4, but I did this because it should have been a better option, since tmap3 will be discontinued soon.
Since I changed my computer, I now re-installed all the packages and the script does not work any more.

The point dataframe is a simple R DF like this

      LAT LONG
[1,] 22.68 54.40
[2,] 20.04 53.84
[3,] 22.78 56.90
[4,] 17.37 54.65
[5,] 21.11 55.26
[6,] 17.57 56.94
[7,] 21.17 55.68
[8,] 17.72 54.04
#shapefile for borders
base <- read_sf("base.shp")
class(base)
#[1] "sf"         "tbl_df"     "tbl"        "data.frame"
#sets a bounding box for the map
box_base <- st_bbox(c(xmin = 51.10, xmax = 59.90, ymax = 16.14, ymin = 26.9), crs = st_crs(4326))
#points
pnts_sf <- st_as_sf(df, coords = c("LAT", "LONG"), crs = 4326)

#reads stamen raster
base_stamen.terra <- terra::rast("base_stamen_b.tif")
class(base)
#[1] "SpatRaster"
#attr(,"package")
#[1] "terra"

# OR FOR A REPRODUCIBLE EXAMPLE 
library(spDataLarge)
base_stamen = read_stars(system.file("raster/landsat.tif", package = "spDataLarge")) 

#map
tmap_mode("plot")
tm_shape(base_stamen.terra) +
    tm_rgb(tm_mv(c("band1", "band2", "band3"))) +
    tm_shape(base)+
    tm_borders()+
    tm_shape(pnts_sf, bbox=box_base)+
    tm_dots(size=0.2)+
    tm_compass(type = "arrow", position = c("right", "top"), size = 2) +
    tm_scale_bar(breaks = c(0, 100, 200), text.size = 0.5)

This produces the following error:

Error in tm_mv(c("band1", "band2", "band3")) : 
  could not find function "tm_mv"

Do you have an idea why the function tm_mv is not recognised?

@olivroy
Copy link
Contributor

olivroy commented Aug 26, 2024

Hi @r-poloni , you can try tm_vars()! This is indeed a change that happened during tmap v4 development! Thanks for testing tmap v4 and let us know if something else is not working as expected!

tm_vars(c("band1", "band2", "band3"), multivariate = TRUE)

Let me know if it works as expected. See #819 for details.

I edited your comment slightly to make sure code was displayed. You need to use 3 back ticks ```

@r-poloni
Copy link
Author

Hi! Sorry, I read the issue and also the news about version 4, but when I saw that they adviced the use of tm_mv I didn't read further. My bad!
Thank you, the tm_vars() works perfectly indeed!

@olivroy olivroy closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants