wrong class allocation when using breaks = "jenks" (should be right-closed)
bergest opened this issue · 1 comments
bergest commented
bonjour
j'ai réalisé une carte avec mapsf et tmap
le résultat est différent entre mapsf et tmap
pour cette carte Schoelcher qui a la densité 949.68342 ne devrait pas être dans la classe 950 1895
voici le code
cordialement
# sur mon poste
library(dplyr)
library(sf)
library(oceanis)
library(mapsf)
library(tmap)
data("palettes_insee")
rouge_3 <- palettes_insee$Insee_Rouge_0N3P
mtq <- mf_get_mtq()
mtq$dens <- as.numeric(mtq$POP /st_area(mtq$geom)) * 1000000
mf_base(mtq)
mf_choro(x = mtq ,
var = "dens",
breaks = "jenks",
pal = rouge_3,
n = 3,
leg_pos = "bottomleft",
leg_title = "densité par km²",
leg_val_rnd = 0,
add = TRUE)
# mf_label(x = mtq, var = "LIBGEO", overlap = FALSE,
# col = "black", cex = 0.8)
mf_get_breaks(x = mtq$dens, nbreaks = 3, breaks = "jenks")
# [1] 33.3211 403.1027 949.6834 1894.8637
# avant derniere densite Schoelcher 949.68342
# dernière densite Fort-de-France 1894.86366
# args(tm_fill)
tm_shape(mtq) +
tm_borders(lwd = 1) +
tm_fill(col = "dens",
palette = rouge_3,
title = "densité par km²",
style = "jenks",
n = 3,
legend.is.portrait = FALSE
) +
tm_legend(position=c("left", "bottom"))
@rCarto edit: format code
rCarto commented
Good catch @bergest
It should be fixed now:
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE
library(mapsf)
mtq <- mf_get_mtq()
mtq$dens <- as.numeric(mtq$POP / st_area(mtq$geom)) * 1000000
mf_map(
x = mtq ,
var = "dens",
type = "choro",
breaks = "jenks",
nbreaks = 3,
leg_pos = "bottomleft",
leg_title = "Densité par km²",
leg_val_rnd = 1
)
Created on 2023-02-14 with reprex v2.0.2
"jenks" is an exception among the methods offered by classInt
, it has to be right-closed.
It has to use something like
] 15 - 20 ]
] 10 - 15 ]
] 5 - 10 ]
[ 2 - 5 ]
instead of
[ 15 - 20 ]
[ 10 - 15 [
[ 5 - 10 [
[ 2 - 5 [