riatelab / cartography

Thematic Cartography for R
http://riatelab.github.io/cartography/docs/
399 stars 46 forks source link

Bug on waffleLayer #71

Closed dieghernan closed 4 years ago

dieghernan commented 4 years ago

There is a small bug on waffleLayerdue to use naming of 'X','Y' coordinates https://github.com/riatelab/cartography/blob/af37610ee6a6c1c5b9bb3ba31aec7013762f6af2/R/waffleLayer.R#L137-L138

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