GithubHelp home page GithubHelp logo

Comments (6)

rpruim avatar rpruim commented on August 21, 2024

@dtkaplan proposed something along the lines of

gf_choropleth(income ~ state, data = Crimes, map = US)

This looks clean, but still leaves some things to be determined:

  1. What aesthetic is income mapped to?
  • fill most likely, but at least alpha and fill make sense here. Are we going to force one? Allow either? Have two functions, one for each?
  1. What data structure is map?
  • must users come up with a map? are we only supporting certain maps?
  1. How are data and map merged?
  • presumably there must be a key that is used to merge the data together. how is it specified?
  1. merging the data can be slow. For repeated maps that differ only in how the data are displayed and not the data themselves, it would be nice to avoid repeatedly doing the merge. Perhaps it is better to think of map creation as a two step process. In step one, the data are prepared and merged. Once that has happened, the plot itself can be created and modified.
  2. income is not "positional" and so doesn't fit as well with our current formula approach. (At least it is unusual in this regard.)
  3. Given some of the other mapping options out there, is this the best place to devote ggformula resources?

from ggformula.

rpruim avatar rpruim commented on August 21, 2024

Now that ggplot2 will have geom_sf(), perhaps we can build gf_sf() to mimic. Need to explore.

from ggformula.

rpruim avatar rpruim commented on August 21, 2024

First attempt is functional. Improvements/examples/documentation may be added/refined later.

library(ggformula)
theme_set(theme_bw())
library(maps)
MI <- sf::st_as_sf(map("county", "michigan", plot = FALSE, fill = TRUE))
gf_sf(fill = ~factor(nchar(ID)), data = MI) %>% gf_refine(coord_sf())

from ggformula.

dtkaplan avatar dtkaplan commented on August 21, 2024

This is great!

from ggformula.

nicholasjhorton avatar nicholasjhorton commented on August 21, 2024

I concur. But I now worry that the documentation/overview is out of date for both ggformula and mosaic and wonder if a separate issue should be created about how to help instructors get a comprehensive list of the functionality of these packages.

from ggformula.

rpruim avatar rpruim commented on August 21, 2024

I've added an example to the vignette.

if (require(maps) && require(mosaic) && require(dplyr) && require(sf) && require(purrr)) {
  USshape <- 
    sf::st_as_sf(maps::map('state', plot = FALSE, fill = TRUE)) %>%
    dplyr::mutate(
      name_length = nchar(ID),
      centroid = purrr::map(geometry, st_centroid),
      coords_x = purrr::map_dbl(centroid, 1),
      coords_y = purrr::map_dbl(centroid, 2)
    ) 
    
  gf_sf(fill = ~ factor(name_length), color = "white", data = USshape, alpha = 0.5) %>%
    gf_sf(data = sf::st_centroid(USshape), color = "white", alpha = 0.5, size = 3) %>%
    gf_text(coords_y ~ coords_x, label = ~ ID, color = "gray20", size = 2) %>%
    gf_labs(x = "", y = "") %>%
    gf_refine(mosaic::theme_map(), theme_bw()) %>%
    gf_labs(fill = "name length")
}

Created on 2018-06-01 by the reprex package (v0.2.0).

from ggformula.

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.