riatelab/cartography

Bug on waffleLayer

dieghernan opened this issue · 0 comments

There is a small bug on waffleLayerdue to use naming of 'X','Y' coordinates

cartography/R/waffleLayer.R

Lines 137 to 138 in af37610

xcenter <- df[i, "X"] - (xx * cellsize / 2)
ycenter <- df[i, "Y"] - (nh * cellsize / 2)

If the dataset x has any variable already named like that the layer uses that value instead the centroids. See here:

library(sf)
library(cartography)

mtq <- st_read(system.file("gpkg/mtq.gpkg", package = "cartography"),
               quiet = TRUE)
# number of employed persons
mtq$EMP <- mtq$ACT - mtq$CHOM
#mtq$X <- 700000
mtq$Y <- 1620000

par(mar=c(2,2,2,2))

plot(st_geometry(mtq), axes=TRUE)
waffleLayer(
  x = mtq,
  var = c("EMP", "CHOM"),
  cellvalue = 100,
  cellsize = 400,
  add=TRUE
)

image

I prepared a small PR. Regards