Skip to content

Advice on reproducible map_coloring? #32

Description

@MatthieuStigler

Hi

I was wondering whether it is possible to have a replicable output with map_coloring, i.e. that is constant across calls? This is particularly useful when one is trying to use testhat snapshots.

I realize that setting minimize=TRUE avoids the call to sample(), so that is already a workaround. Should one want more colors than the strict minimum, the output seems to change each time. Do you see an easy way to add maybe a seed argument?

Thanks!

library(tmaptools)
packageVersion("tmap")
#> [1] '3.3.2'
packageVersion("tmaptools")
#> [1] '3.1.1'
library(tmap)

data(World)

color <- map_coloring(World, palette="Pastel2")
color2 <- map_coloring(World, palette="Pastel2")
all.equal(color, color2)
#> [1] "152 string mismatches"


color <- map_coloring(World, palette="Pastel2", minimize=TRUE)
color2 <- map_coloring(World, palette="Pastel2", minimize=TRUE)
all.equal(color, color2)
#> [1] TRUE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions