Closed hagertynw closed 2 weeks ago
Which version do you have? Mine is on Win10:
> packageVersion("tmap")
[1] ‘3.99.9002’
and it works for me:
tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "br_bg"))
tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "-br_bg"))
> packageVersion("tmap")
[1] ‘3.99.9003’
on Win10 Enterprise.
Do you know how to install an earlier version from Github?
This should do that:
remotes::install_github("r-tmap/tmap@4b394a317de56c2c4605379cd958954246cb5860")
Thank you. I used that link to install tmap 3.99.9002, updated all package dependencies, and started a new session in which I loaded nothing besides tmap. It still doesn't work. Both lines of code above produce the first map, in which Russia is teal. I also tried tmap_save in case it was an issue with the RStudio viewer, and the output images are also identical.
In view mode I get this error message, in case it is a clue. I don't think I understand enough of how the color values are generated to interpret it. Appreciate the help.
> ttm()
ℹ tmap mode set to "view".
> tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "-br_bg"))
Registered S3 method overwritten by 'jsonlite':
method from
print.json jsonify
Warning message:
In checkDim(x, data) :
Length of color vector does not match number of data rows.
The vector is repeated to match the number of rows.
> tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "br_bg"))
Warning message:
In checkDim(x, data) :
Length of color vector does not match number of data rows.
The vector is repeated to match the number of rows.
I am sorry, I am not skilled enough to fix the issue. But I checked and found that a commit seems to have broken it.
This should fix your issue for now.
## install the working version of the tmap package
# remotes::install_github("r-tmap/tmap@05bd6c605123cbc773cc09a86b39d60540f51163") # does not work
remotes::install_github("r-tmap/tmap@4b754be3143bbe0819920e28a3bfb227713638f8") # works
library(tmap)
#>
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#>
#> rivers
packageVersion("tmap")
#> [1] '3.99.9002'
tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "br_bg"))
#> Multiple palettes called "br_bg" found: "brewer.br_bg", "matplotlib.br_bg". The first one, "brewer.br_bg", is returned.
tm_shape(World) + tm_polygons(fill = "area", fill.scale = tm_scale(values = "-br_bg"))
#> Multiple palettes called "br_bg" found: "brewer.br_bg", "matplotlib.br_bg". The first one, "brewer.br_bg", is returned.
Created on 2024-11-12 with reprex v2.1.1
Thank you! That solved my immediate problem.
Thx for this bug report @hagertynw Now fixed in the latest dev version.
In tmap v4, it would be very helpful to be able to reverse the values of a color palette. I thought it could be done with a negative sign in front of the palette name, but it doesn't seem to work. These two lines produce identical maps for me:
I couldn't find another argument in the documentation that would accomplish this. If there is another way to do it that I missed please let me know. Thanks!