Giter VIP home page Giter VIP logo

Comments (5)

dieghernan avatar dieghernan commented on August 19, 2024 3

Following the WIP of @rCarto , I have been working on further develop a feature like that: https://github.com/dieghernan/cartography/blob/histv2/R/maphist.R

There is still a point on thinking if this needs to be integrated into a legend or if it can live as standalone feature. In case of integration, the problem on legendChoro is that it doesn't handle real data inputs, just labels, so a call to histogram there would need major changes.

A example on how the WIP compares with tmap so far:

library(sf)
library(tmap)
mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"))
mtq$chomage=mtq$CHOM/mtq$ACT
cols=carto.pal("wine.pal",4)

# TMAP OPTION--------
tm_shape(mtq) +
  tm_borders(col = 'white', lwd = 0.3) +
  tm_fill(col = 'chomage', title = 'Chomage', legend.hist = TRUE,
          palette = cols) +
  tm_legend(legend.outside = TRUE)

image

# CARTOGRAPHY OPTION--------
par(mar=c(0,0,0,3))
brks=as.double(pretty(mtq$chomage))
choroLayer(mtq,var="chomage", breaks = brks, col=cols,
           legend.pos="topright", legend.title.txt="Chomage",
           legend.values.rnd=2)

maphist(mtq$chomage,breaks = brks,pos="right", col=cols)

image

from cartography.

dieghernan avatar dieghernan commented on August 19, 2024 1

An attempt to integrate it:

library(cartography)
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"))
# Population density
mtq$POPDENS <- 1e6 * mtq$POP / st_area(x = mtq)
par(mar = c(0.5,0.5,2,0.5))
bks <- getBreaks(mtq$POPDENS, method = "quantile", nclass = 6)
cols <- carto.pal(pal1 = "wine.pal", 6)
choroLayer(x = mtq, var = "POPDENS", breaks = bks, col = cols,
           border = NA, legend.title.txt = "Population\nDensity",
           legend.hist = TRUE) #NEW PARAMETER
layoutLayer("Testing histogram", theme = "wine.pal")

image

from cartography.

rCarto avatar rCarto commented on August 19, 2024

Hi,
Yes, that would be a nice feature.
I already tried something like that here.
I'm not sure that's the way it should be done in cartography.

from cartography.

rCarto avatar rCarto commented on August 19, 2024

WIP here : https://github.com/riatelab/cartography/tree/hist

from cartography.

chrijo avatar chrijo commented on August 19, 2024

Hello @dieghernan,

thanks, both solutions look great. However, I agree with you in that the standalone Version seems more felxible. Great job!

from cartography.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.