Pages Menu
TwitterRss
Categories Menu

Posted by on Jun 7, 2012 in Featured Maps, R Spatial, Slideshow, Visualisation | 14 comments

Mapping the World’s Biggest Airlines

The map above shows the routes flown by the top 7 airlines (by international passenger distance flown). The base map shows large urban areas and I have attempted to make it look a bit like the beautiful “Earth at Night” composite image produced by NASA. You can clearly see a relationship between where people live and where the big carriers fly to across Europe and the US but India and much of China have relatively few routes. I expect much of the slack is picked up by smaller airlines in these countries but they must represent key growth areas the world economy becomes increasingly driven by the east. This map isn’t meant to be comprehensive- I just wanted to make another example of a visualisation with ggplot2.

How I did it

Plotting great circles has become an increasingly popular thing to do with R (because they look cool) and the excellent flight path data freely available from the OpenFlights website provides a neat data source to play around with. There are several tutorials out there but none of them (to my knowledge) apply apply colour value to the arcs based on a relevant variable in the datafile or make much of the underlying base map. For the Tufte fans out there this is means an important opportunity for maximising data ink has been missed.

The first step was to calculate the great circles with the flight data. The Anthrospace blog has a good tutorial on this so I won’t replicate the code here. I would warn you that it is a little tricky to sort out. For the R pros out there if you have a refinement on the code please comment below.

The next step was to source the world urban area boundaries. These can be found on the Natural Earth Data website. Direct link. In the code below I have simplified these and coloured them in the plot to reflect the colours in the NASA image. I have also coloured the background and continents accordingly. Without the great circle arcs your basemap should look a bit like this (I’m really pleased with how it came out).

With this layer in place you can now draw whatever you want on top of it. In this case it is the flight arcs. I then added a few annotations and moved the key etc in Inkscape for the final image.

Load libraries
library(ggplot2)
library(maps)
library(rgeos)
library(maptools)
gpclibPermit()

Load in your great circles (see above for link on how to do this). You need a file that has long, lat, airline and group. The group variable is produced as part of the Anthrospace tutorial.
gcircles

Get a world map
worldmap

Load in your urban areas shapefile from Natural Earth Data
urbanareasin

Simplify these using the gsimplify function from the rgeos package
simp

Fortify them for use with ggplot2
urbanareas<-fortify(simp)

This step removes the axes labels etc when called in the plot.
xquiet yquiet<-scale_y_continuous("", breaks=NA, lim=c(70,-70))
quiet<-list(xquiet, yquiet)

Create a base plot
base

Then build up the layers
wrld<-c(geom_polygon(aes(long,lat,group=group), size = 0.1, colour= "#090D2A", fill="#090D2A", alpha=1, data=worldmap))
urb

Bring it all together with the great circles
base+wrld+urb+geom_path(data=gcircles, aes(long,lat, group=group, colour=airline),alpha=0.1, lineend="round",lwd=0.1)+coord_equal()+quiet+opts(panel.background = theme_rect(fill='#00001C',colour='#00001C'))

Share on Facebook
Bookmark this on Google Bookmarks
Share on reddit
Bookmark this on Digg
Share on StumbleUpon
Share on LinkedIn

14 Comments

  1. Nice work James…

  2. I had a problem on the last step:

    Error in grid.Call.graphics(L_setviewport, pvp, TRUE) :
    Non-finite location and/or size for viewport

  3. should import maptools for readShapePoly

    library(maptools)

    • Sorry I missed that- thanks

  4. still does not work

  5. NASA is working really great the picture taken by NASA is awesome.

  6. Hi there,

    How can i get color for “airline” variable? and the flight_gcircles.csv?

    Thanks

  7. Hi,

    runs fine for me, except for the last command gives me

    breaks = NA is deprecated. Please use breaks = NULL to remove breaks in the scale. (Deprecated; last used in version 0.8.9)

    Is that because I’m using ggplot2 0.9 ? Any workaround?

  8. Very interesting visualization. Do you have the steps documented anywhere explaining how you created the base map from the natural earth files?

  9. hello sir you have done a great job, I have confusion about what is urb stands for in the code and how to make layer file of urban areas

  10. Great tutorial in deed. I used your code to project my data. I haven’t manage however to change SpatialPoints into SpatialPolygons(DataFrame)… I’ve tried several versions of your:
    urbanareas<-fortify(simp)
    like:
    urbanareas<-ggplot2:::fortify.SpatialPolygonsDataFrame(simp)
    urbanareas<-ggplot2:::fortify(simp)
    urbanareas<-fortify.SpatialPolygonsDataFrame(simp)

    I have to be missing something…
    I would really appreciate all your suggestions.

  11. Hi James, I recently found this link. Thank you very much for sharing your work. I needed to invest quite a bit of time, but I managed to replicate what you did. Given what others said in comments, I would like to leave some information for some others who may find it useful.

    1) Urban data
    You need to download data from this web link at the moment.

    http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-urban-area/

    Then, you need a line like this.

    urbanareasin <- readShapePoly("ne_10m_urban_areas.shp")

    2) xquiet and yquiet

    You can set up these variables. But you can add them like this when you draw a plot using ggplot2.

    scale_x_continuous(breaks = NULL) +
    scale_y_continuous(breaks = NULL)

    3) urb
    nayan seemed confused. urb is similar to wrld, so James did not probably leave information. I came up with this, and this works for me.

    urb <- c(geom_polygon(aes(long, lat, group = group),
    size = 0.3,
    color = "#ffffff",
    fill = "#ffffff",
    alpha = 1,
    data = urban areas))

    4) ggplot2
    Since this post was written, the ggplot2 package has been updated. I wrote the following to replicate James' work.

    base + wrld + urb + geom_path(data = gcircles, aes(long, lat, group = group, color = Airline),alpha = 0.5, lineend = "round", lwd = 0.3) +
    coord_equal() +
    scale_x_continuous(breaks = NULL) +
    scale_y_continuous(breaks = NULL) +
    theme(axis.title.x = element_blank()) +
    theme(axis.title.y = element_blank()) +
    theme(panel.background = element_rect(fill = '#00001C', color = '#00001C')) +
    theme(legend.position = "none")

  12. Hi, is it possible for me to use the “mapping of the world’s biggest airline” image, on my webpage?

    Thank you!

    • (Looking through the profiles of MSN members); Sites to match couples (Perfectmatch, match, etc) and Relationship sites
      (Passion, Adult Friend Finder, etc). That re-validation comes in a female user in our site within 30 or 40 minutes—as a number of guys are knocking at her door and professing their desire to be with her,
      ” he says. Sources: Wikipedia ( msnbc ( Los Angeles Times (.

Trackbacks/Pingbacks

  1. Visualising Flows: Great Britain Journey-to-Work - [...] such as Paul Butler’s global facebook friend’s map, and maps of global trade and flight patterns. Inspired by these, I’ve …
  2. Thought this was cool: 中国国内航线信息的可视化 « CWYAlpha - [...] 上图是对国内机场和航线信息进行了一个简单的可视化。圆点表示了中国163个机场的位置,线条显示了5381条航线。之前曾在这个网站上见到了作者用R语言来对全世界的航线进行可视化。正所谓见贤思齐,本图就是模仿山寨的结果。但是这个图的生成没有原文那么复杂,所用到的地理图形包和步骤也与原例略有不同,比较失败的是没有展现出原图的夜景效果。具体实施的步骤如下: [...]
  3. Mao's steps | Keep walking - [...] http://spatialanalysis.co.uk/2012/06/mapping-worlds-biggest-airlines/ Like this:LikeBe the first to like this. This entry was posted in Uncategorized. Bookmark the permalink. …
  4. How new technology has influenced Data Visualisations « tms30x30 - [...] change moving away from normal bar and pie charts to a new world of possibilities; from mapping the world’s …
  5. R时代,你要怎样画地图? | 统计之都 - [...] Earth At Night: Mapping the World’s Biggest Airlines [...]
  6. [R] ggplot2: mapping worlds biggest airlines | My Study Notes - [...] James Cheshire posted a tutorial on how to generate this nice chart. here is the link. [...]
  7. What’s so Great About a World Flight Paths Map? | Spatial.ly - [...] to show the extent of the Earth and this serves to frame the map and enhance the colours. When I mapped …
  8. 40 Jenis Peta yang tidak dipelajari di Sekolah | whatanewsnetwhatanewsnet - […] Via: Spatial.ly: Mapping the World’s Biggest Airlines […]

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>