r-spatial.org icon indicating copy to clipboard operation
r-spatial.org copied to clipboard

Re: latest sf/ggplotblog posts, facetting, rnaturalearth

Open adrfantini opened this issue 6 years ago • 5 comments

These are 2 suggestions for improving the three (really good) blog posts recently published regarding plotting spatial data with ggplot2 and sf.

I wasn't sure where to leave these, as I do not know how to reach the authors.

  1. I personally use facetting in ggplot quite often, way more often than I use cowplot or patchwork to arrange plots manually. Of course facets work well with sf data, they look clean and you do not have to bang your head around to find the proper size ratios. The downside is that they are, of course, much less flexible. E.g. you cannot plot two different physical dimensions next to one another, but you can plot the same thing from different datasets.
  2. I find grabbing spatial data from rnaturalearth, rnaturalearthhires and rnaturalearthdata is much more convenient than using maps or rworldmap. These packages interface to http://www.naturalearthdata.com/, optionally providing sf objects as output. One neat and useful thing is that if you grab, for example, both country boundaries and municipalities, they match exactly, avoiding small and ugly differences which come from using datasets from different sources.

adrfantini avatar Oct 26 '18 13:10 adrfantini

Great suggestions; the authors are @melimore86 and @basille . Maybe room for a jointly written part 4?

edzer avatar Oct 26 '18 17:10 edzer

Hey @adrfantini, both suggestions are indeed very good! The first is not something we use very often, but I can see the benefits — that would have been a good fit on Part 3. As for the second suggestion, I actually never used those packages! It would be great indeed to look into them, and include them in our original pieces!

I like the suggestion of @edzer , although I don't know if @melimore86 would be available to work on this one. I'd be happy to help and guide this part. Would you know how to make it a consistent piece (i.e. Part 4, as suggested by @edzer)?

basille avatar Oct 29 '18 04:10 basille

Hi @basille , I have personally never used RMD, but It does not look too complicated, I think I could try and I'd be glad to. Problem is I do not have any spare time before the beginning of January, due to annoyances like having to write a thesis and such: I do not want to commit to other projects right now, however small they are.

I'll be happy to do this in January. In the meantime, if you want to implement my suggestions your self, feel free of course.

adrfantini avatar Oct 29 '18 07:10 adrfantini

Hello,

Great suggestions. I am taking a look at ggplot faceting to incorporate that into Tutorial 3. I will also look in those packages mentioned to compare the differences.

Thanks, Mel M

melimore86 avatar Oct 29 '18 15:10 melimore86

Hello all, Firstly great three posts, 2ndly great suggestions by @adrfantini.

I developed rworldmap and rnaturalearth and I was just about to suggest using rnaturalearth.

rworldmap : older, no longer in active development, does lots of things rnaturalearth : newer, active development, just the data

I would suggest replacing this

library("rworldmap")
library("rworldxtra")
world <- getMap(resolution = "high")

with:

library(rnaturalearth)
world <- ne_countries(scale='medium')

or you can get it to do the sf conversion for you world <- ne_countries(scale='medium', returnclass = 'sf')

You would also need to change the install to rnaturalearth and rnaturalearthdata.

I think the only other thing you would need to alter in the posts is to change the fieldnames NAME and POP_EST to lowercase to fit with the more recent Natural Earth data.

Happy to check further for you.

I should probably ad something to the rworldmap readme pointing people to rnaturalearth.

Andy

andysouth avatar Oct 30 '18 17:10 andysouth