Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFactor order for colours #138
Comments
|
Example:
Result: Expected behaviour for factors is a discrete colour scale with level values as labels, instead of continuous colour scale with level order as values. When cast to character we get character labels, but the order is lost. The levels are ordered as "B" first and the "A", but this is lost when converting to character.
|
|
If you install the latest version, plus the dependencies, you should now see this working devtools::install_github("SymbolixAU/colourvalues", force = TRUE )
devtools::install_github("SymbolixAU/spatialwidget", force = TRUE )
devtools::install_github("SymbolixAU/mapdeck", force = TRUE )
library(mapdeck)
library(tibble)
library(sf)
data <- tibble::tibble(
lat = c(49.25,49.2)
, lng = c(-123.1,-123)
, value = factor( c("A","B"), levels = c("B","A"))) %>%
sf::st_as_sf(coords = c("lng", "lat"), crs = 4326, agr = "constant")
str( data )
set_token( read.dcf("~/.mapbox", fields = "MAPBOX") )
data$value2 <- as.character( data$value )
mapdeck(style = mapdeck_style('dark')) %>%
add_sf(
data = data
, fill_colour = "value"
, stroke_colour = "value2"
, tooltip = "value"
, legend = TRUE
, radius = 500
)
|
|
Thanks, that works for me. One change I noticed is that add_sf does not seem to be as tolerant any more. It used to work with geometry type GEOMETRY, now I need to st_collection_extract("POLYGON") to get it to show up. |
|
Could you open a new issue with an example? |



Keep the order of a factor variable when colouring