6

Here is an example:

library(sf)
library(mapview)

data(meuse)

d <- st_as_sf(meuse, coords = c("x", "y"))
d1 <- d[sample(nrow(d), 20), ]
d2 <- d[sample(nrow(d), 20), ]

mapview(list(d1, d2))

Both layers, d1 and d2, and displayed using the same color. How can I chose different colors, say red for d1 and blue for d2?

1 Answer 1

9

You have to add arguments for colors, see ?mapview. In your case for main color you can use col.regions=list("red","blue") and col=list("red","blue") for outlines. So whole code could be like this:

library(sp)
library(sf)
library(mapview)

data(meuse)

d <- st_as_sf(meuse,coords =  c("x","y"))
d1 <- d[sample(nrow(d),20),]
d2 <- d[sample(nrow(d),20),]

mapview(list(d1,d2),col.regions=list("red","blue"),col=list("red","blue"))
3
  • 4
    Or use + to concatenate the 2 layers: mapview(d1, col.regions = "red") + mapview(d2, col.regions = "blue")
    – TimSalabim
    Feb 13, 2019 at 10:26
  • Great, thanks! What I tried before was col.regions=c("red","blue"),col=c("red","blue")... which didn't work. It seems to make a difference if you provide lists or vectors as arguments to col.regions. Thanks!
    – Funkwecker
    Feb 13, 2019 at 12:44
  • I feel like it shouldn't make a difference, but to be honest, the list method of mapview has become my personal nemesis! I am the mapview developer BTW. If you feel strongly about this, please open an issue on the mapview github repo.
    – TimSalabim
    Feb 13, 2019 at 19:51

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .