All Projects → RobertMyles → flagfillr

RobertMyles / flagfillr

Licence: other
Use flags as fills for ggplot2 maps. (WIP)

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to flagfillr

30DayMapChallenge
My contributions to the #30DayMapChallenge 2019, a daily challenge focusing on spatial visualizations happening throughout November.
Stars: ✭ 170 (+639.13%)
Mutual labels:  ggplot2, maps
react-vector-maps
🗺 A React component for interactive vector maps of the world and 100+ countries
Stars: ✭ 112 (+386.96%)
Mutual labels:  maps
is-sea
🌊 Check whether a geographic coordinate is in the sea or not on the earth.
Stars: ✭ 34 (+47.83%)
Mutual labels:  maps
org
No description or website provided.
Stars: ✭ 15 (-34.78%)
Mutual labels:  maps
rworkshops
Materials for R Workshops
Stars: ✭ 43 (+86.96%)
Mutual labels:  ggplot2
geowarp
Super Low-Level Raster Reprojection and Resampling Library
Stars: ✭ 20 (-13.04%)
Mutual labels:  maps
NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (+95.65%)
Mutual labels:  maps
map-machine
Python renderer for OpenStreetMap with custom icons intended to display as many map features as possible
Stars: ✭ 82 (+256.52%)
Mutual labels:  maps
polylineencoder
A C++ implementation of Google Encoded Polyline Algorithm Format (encoder/decoder)
Stars: ✭ 15 (-34.78%)
Mutual labels:  maps
football-team-flags
Flags from national teams made with css 🏳
Stars: ✭ 19 (-17.39%)
Mutual labels:  flags
leaflet-locationpicker
Simple location picker on Leaflet map
Stars: ✭ 31 (+34.78%)
Mutual labels:  maps
Rstudio TableContest 2020
📺 Table showing an "Overview and Series Trends of the Best TV Shows on IMDb" – My Contribution to the Rstudio Table Contest 2020
Stars: ✭ 16 (-30.43%)
Mutual labels:  ggplot2
chilemapas
Mapas terrestres de Chile con topologias simplificadas.
Stars: ✭ 23 (+0%)
Mutual labels:  maps
google-maps-at-88-mph
Google Maps keeps old satellite imagery around for a while – this tool collects what's available for a user-specified region in the form of a GIF.
Stars: ✭ 93 (+304.35%)
Mutual labels:  maps
30diasdegraficos
30 tipos de gráficos hechos con R, con datos y código reproducible.
Stars: ✭ 47 (+104.35%)
Mutual labels:  ggplot2
carto-react-template
CARTO for React. The best way to develop Location Intelligence (LI) Apps usign CARTO platform and React
Stars: ✭ 24 (+4.35%)
Mutual labels:  maps
EasyWayLocation
This library contain all utils related to google location. like, getting lat or long, Address and Location Setting dialog, many more...
Stars: ✭ 142 (+517.39%)
Mutual labels:  maps
poor-maps
Maps and navigation for Sailfish OS
Stars: ✭ 42 (+82.61%)
Mutual labels:  maps
Long-Map-Benchmarks
Benchmarking the best way to store long, Object value pairs in a map.
Stars: ✭ 32 (+39.13%)
Mutual labels:  maps
layer
Create stacked tilted maps
Stars: ✭ 97 (+321.74%)
Mutual labels:  ggplot2

flagfillr

flagfillr is a little package for R that makes it easier to use flags as fills (i.e. backgrounds) for ggplot2 maps.

Installation

You can install flagfillr from github with:

# install.packages("devtools")
devtools::install_github("RobertMyles/flag_fillr")

It's not on CRAN because it depends on development versions of some packages, and because the size of the 1000px flags renders it difficult for CRAN to accept. So it'll probably never be on CRAN, but hey, that's OK.


Important Note: flagfillr works with ggplot2's geom_sf(), which is currently only available in the current development version of ggplot2 (version 2.2.1.9000).

Why? For the love of god, why??!!!

Well, I'm happy you asked. Imagine you saw the following image, from the Drunkneysian, taken from here:

It's an interesting subject, and a handy visual summary of the data. But...


...isn't this sooo much nicer?

(The section below shows how to make it.) Ok...it depends on some knowledge of flags, but look! They're so purty. And, I mean, just look at Africa...

That's pure unadulterated awesome-sauce, right there. (I know, I know. It's not data visualization in the case of the Africa plot. But still...) I would argue that it's easier to process the flag map in the above Brazilian case, especially for well-known flags. Anyway, I'm not slighting the Drunkneysian plot, very nice as it is. flagfillr merely offers a pretty alternative, and we all like pretty things in our lives, now don't we?

Using flagfillr

You can use flagfillr in two ways: you can supply your own data, and use the function flag_fillr_data() to make some maps, or you can make pretty pictures with flag_fillr_country(), flag_fillr_continent() and flag_fillr_state().

So with the latter option, you can do this:

flag_fillr_states("United States of America")

And this:

flag_fillr_continent("Asia")

And even this:

flag_fillr_country("Mexico")

Although I had to take out the 1000px resolution flags because of their size, so your Mexican flag won't look quite as amazing.

Be aware: some of these can take some time to plot, especially at higher resolutions and larger sizes.

Ok. The main reason I made this package is to use it with data, even though those 'picture' maps are totes awesome. To recreate something like the Brazilian economic-partners map above, you'll be using the flag_fillr_data() function, and you'll need the following:

  • a data.frame with a column for the base territory (where we'll map) and a column for the partners (the flags we'll put there). The simplest case is to just call these columns country (if you're plotting flags on entire countries) and partner. If you want to plot flags on states inside a country (like the Brazil example above), supply a state column. The country column is then optional. Note that the name of the country is always necessary, either supplied through country or country_col.
  • if you have data that you'd rather not rename, you can supply the 'partner' and 'country'/'state' columns, using partner_col, country_col and state_col. Here's how I made that map above (the code is long 'cos Brazil has lots of states...):
library(flagfillr)
library(rnaturalearth)
library(dplyr)
library(stringi)

br <- ne_states(country = "Brazil", returnclass = "sf")
trade <- tibble(
  country = "Brazil",
  state = br$name,
  partner = NA_character_) %>% 
  mutate(state = stri_trans_general(state, "Latin-ASCII"),
         partner = case_when(
          state == "Acre" ~ "Peru",
          state == "Alagoas" ~ "China",
          state == "Amapa" ~ "United States of America",
          state == "Amazonas" ~ "Argentina",
          state == "Bahia" ~ "China",
          state == "Ceara" ~ "United States of America",
          state == "Distrito Federal" ~ "China",
          state == "Espirito Santo" ~ "United States of America",
          state == "Goias" ~ "China",
          state == "Maranhao" ~ "Canada",
          state == "Mato Grosso" ~ "China",
          state == "Mato Grosso do Sul" ~ "China",
          state == "Minas Gerais" ~ "China",
          state == "Para" ~ "China",
          state == "Paraiba" ~ "United States of America",
          state == "Parana" ~ "China",
          state == "Pernambuco" ~ "Argentina",
          state == "Piaui" ~ "China",
          state == "Rio de Janeiro" ~ "China",
          state == "Rio Grande do Norte" ~ "United States of America",
          state == "Rio Grande do Sul" ~ "China",
          state == "Rondonia" ~ "Hong Kong",
          state == "Roraima" ~ "Venezuela",
          state == "Santa Catarina" ~ "United States of America",
          state == "Sao Paulo" ~ "United States of America",
          state == "Sergipe" ~ "Netherlands",
          TRUE ~ "China"
          ))

flag_fillr_data(trade, country = "Brazil", partner_col = trade$partner, 
                state_col = trade$state, type = "state", 
                resolution = "large", size = "250")

Don't be put off by all those state ==s, remember, you'll be supplying your own data. Here. I had to make it.


So there you go! In the (un)likely event you find yourself pining for flags in a ggplot2 map, flagfillr has got you covered.


Contributions

Pull requests and issues are welcome. I particularly welcome any datasets of flags in png format! The plotting of state-level flags is still a bit messy, and removing islands and far-off territories could be much better. The flags are great, though (Argentina has some good ones).

Related

I should mention that this isn't new: Paul Murrel shows how to do it with grid graphics here. And yes, ggplot2 is based on grid graphics. But I haven't seen a ggplot2 one, so... For images other than flags in plots other than maps, Giora Simchoni's ggwithimages package might be what you're looking for.

Thanks

The main data wrangling function in this package is not painfully slow because the talented Daniel Falbel helped me out with purrr's map2. And I don't have distastrous 'outliers' (get it?) because of the help of the gifted Julio Trecenti. Valeu, gente!

Giora's package also reminded me of this project (I tried and failed about two years ago), so thanks Giora! And his blog post led me to this wonderful SO answer, which set me on my way. Thank you, jalapic and inscaven (I know those are not your real names).

Flags

The flags used in this repo come from Wikipedia. The US state flags come from Civil Services. Thanks to Wikipedia and the contributors of the above-linked projects for their work on making these flags available and easy to get!

to do

  • create more repos of state flag pngs
  • clean up method of removing outliers (France!)
  • different projections?
  • remove data after it gets loaded automatically
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].