dsr icon indicating copy to clipboard operation
dsr copied to clipboard

Maps – tmap, leaflet, sf, spdplyr, cartography, etc.

Open briatte opened this issue 9 years ago • 13 comments

  • https://github.com/mdsumner/spbabel
  • https://github.com/mdsumner/spdplyr
  • https://github.com/edzer/sfr
  • https://cran.r-project.org/web/packages/tmap/index.html
  • https://github.com/Groupe-ElementR/cartography

… and the list goes on: see my blog post on the issue (kind of).

Some folks are putting ideas together on the topic.

U.S. spatial data: https://github.com/martinjhnhadley/statesRcontiguous

briatte avatar Dec 20 '16 00:12 briatte

The easiest solution might be to teach only one method, possibly one that works with both choropleths and geocoded points.

Pinging @rCarto in case he might have some suggestions.

briatte avatar Dec 31 '16 05:12 briatte

IMHO the packages you're mentionning are dealing with very different tasks (as the rspatial discussion makes it clear), using very different paradigms and operating at vastly different levels of maturity.

So I think in the context of an introductory workshop to R, it is important to focus on 1/ a more-or-less coherent paradigm 2/ stable solutions 3/ one of the steps of the workflow @tim-salabim identified.

My advice at this point would be to focus on the rgdal/sp tools to import and contain data, as this is definitely what's most mature at the time. sf is very, very promising but definitely lacks real-worl use-cases at the time, and doesn't allow mapping without converting back to a Spatial* class. Also, spdplyr fits in nicely here.

Then you have two great mapping packages IMHO, cartography and tmap. My personal opinion is that ggplot2 is not really the way forward for mapping, but I know a lot of people, including you, would disagree. The advantage of using ggplot is that students can learn and use a coherent syntax. Now tmap uses a syntax that is not so different, and offers in my opinion a much wider range of possibilities. cartography is also great, because it's made by great geographers, and also have documentation in French (I have to say documentation is definitely one of the cons of tmap at the moment).

joelgombin avatar Dec 31 '16 06:12 joelgombin

I agree that the cited packages are different and unequally advanced.

More thinking aloud below. Basically, to me, there's three choices (leaving Leaflet out).

  1. Tinkering with ggplot2 + helpers. spbabel and spdplyr are ultra-interesting to me. I've briefly exchanged with @mdsumner on Twitter, and read his notes: he is making a lot of progress on releasing "tidy spatial" code. He has also released ggpolypath, which ggspatial is based upon.

    All these tools are nice, but as far as I can tell, none of them are stable. They help ggplot2 deal with spatial data (as does ggalt by improving on coordinates handling), but they help "from the outside". Helping "from the inside" would mean altering/re-thinking many of the ggplot2 fundamentals (my blog notes contain some hints about that).

    I hope that, at some point, all these tools will get bundled together in some nice way. For now, the ggplot2 microverse has ggmap and geom_map, and basic polygon fortifying (apparently with some bugs here and there). That's good enough for many, many basic cases of drawing maps.

  2. Keeping an eye on sf. I hope for geom_sf at some point. It's in the works, but it's at stage 1 out of 10 right now.

  3. cartography and tmap. Both of them look like good choices. The tmap syntax has my preference, because it "feels" tidy. But again: at least 75% of the tmap vignette can be done in ggplot2, and that's a plus if you are teaching a syntax with the hope that it will serve in many circumstances.

briatte avatar Dec 31 '16 14:12 briatte

I can help you ggplot with sf already, if needed. It's good for learning if nothing else.

mdsumner avatar Dec 31 '16 14:12 mdsumner

Hi @mdsumner

Thanks for offering to help.

If you look at the draft syllabus, there is a section on data visualization.

I would like to include a single exercise involving maps, ideally using GADM and involving both choropleths and a 'bubble map' or something like that.

My guess is that the exercise would start with ggplot2/ggmap and then switch to something more appropriate for spatial data.

Here are some candidates for the exercise:

  • https://github.com/davben/arvig
  • https://github.com/SciutoAlex/Historical-Travel-of-US-Secretary-State

Feel free to chime in if you have suggestions for the exercise :)

Cheers,

ƒ

briatte avatar Jan 09 '17 06:01 briatte

P.S. @joelgombin and @rCarto are naturally welcome to submit ideas too!

briatte avatar Jan 09 '17 06:01 briatte

geom_sf is already here in the dev ggplot2: https://github.com/tidyverse/ggplot2/tree/sf

and dev mapview and now leaflet also supports sf: https://github.com/rstudio/leaflet/pull/350

So it will be pretty easy to use, unless you need to teach before those updates are released to CRAN. I probably won't get to explore those links but feel free to ask specific questions.

mdsumner avatar Jan 09 '17 14:01 mdsumner

https://github.com/tidyverse/ggplot2/tree/sf

This rocks, I'll explore and see if I can teach with that (the workshop starts in February).

briatte avatar Jan 09 '17 21:01 briatte

This looks like a map that I'd be happy to reproduce with R:

https://visionscarto.net/global-nuclear-power-database

I'm posting some other suggestions in the other issues of this repo.

briatte avatar Jan 11 '17 05:01 briatte

Well, I may have some ideas on how to reproduce this map. I'll let you know if I managed to.

rCarto avatar Jan 11 '17 23:01 rCarto

Many thanks!

briatte avatar Jan 12 '17 06:01 briatte

The conversation over at tim-salabim/rspatial/issues/9 is getting somewhere.

@edzer just posted a detailed text that links to

  • http://r-spatial.org/
  • http://rspatial.org/

and all the other relevant places to monitor.

The rspatial.org website (which still has a few work-in-progress missing sections) has nice examples of using spplot from sp/raster.

@edzer has also written a very nice list of sp demos:

  • https://edzer.github.io/sp/

… and is continuing the work on sf – 2017 update:

  • http://r-spatial.org/r/2017/01/12/newssf.html

briatte avatar Jan 15 '17 07:01 briatte

Last thing: the new repo to watch for discussions is r-spatial/discuss.

briatte avatar Jan 15 '17 08:01 briatte

Replaced by #30

briatte avatar Apr 25 '23 11:04 briatte