Pages Menu
TwitterRss
Categories Menu

Posted by on Jun 7, 2012 in Featured Maps, R Spatial, Slideshow, Visualisation | 17 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

17 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. エルメス時計スーパーコピー ビート秒針について非常にクールなことはそれがこのメカニズムが働く方法を見ることができる運動の白骨化したオーバービューが存在するということです。実際には、これは私が考えることができる最初の時間を私は死んでいる秒針が実行される(図を見た。私はディウィットの時間の2つの理由のためにこのようにして設計されたデウィット・学界は思っています。1つの特定のからくりを死者の秒針が動くのを許す見解を提供するために、第2のように微妙なのが「これは、確かにではなく、クォーツ時計です。」 http://www.okakaku.com/Super-Copy-195.html

  13. 針を創立しスイスガス表1886年、120年以上の歴史を持つ、称賛には一番人気時計ブランドの一つスイス。ガス針表スイス先進技術設備を採用して、腕時計を各性能はカリスマ抜群で、その高い品質の防水機能、耐震設計と独特な夜光機能、保証ごとにすべて持って針だけガス表恒久の価値は、消費者の好感を受けて尊重。 http://www.bagkakaku.com/vuitton_bag/2/N51207.html

  14. 1375年の個々のコンポーネントから成ると立っている約60センチメートル(約23 . 5インチ)背のユニークなコンスタンチンchaykinコンプトゥスの復活祭の時計は確かに属しました―これまで最も複雑なクロックのうち、実際には、最も複雑なロシアのクロックに応じて、chaykin。40才のロシアの時計屋、宗教のために、すべてのその形で、そして、彼らの異なるカレンダーと象徴性は、特に、本物の情熱です。 モンクレールスーパーコピー これは、彼の前のクロックとキリスト教の、ヘブライ語で腕時計に反映される、とイスラムのシンボルとカレンダー。 http://www.eevance.com/tokei/vuitton

  15. 針を創立しスイスガス表1886年、120年以上の歴史を持つ、称賛には一番人気時計ブランドの一つスイス。ガス針表スイス先進技術設備を採用して、腕時計を各性能はカリスマ抜群で、その高い品質の防水機能、耐震設計と独特な夜光機能、保証ごとにすべて持って針だけガス表恒久の価値は、消費者の好感を受けて尊重。 http://www.gowatchs.com/brand-214.html

  16. およそ1年前、私は私のマーク・カーソンkaラ・スポーツ腕時計はどうなるのだろう、ダイヤルと手を設計したが、特定の思想は当時のストラップに与えられました。私は、バーゼル2015年から帰ったとき、私は座った一つのゴールの設計は、高セキュリティストラップシステムを利用することができたのは、曲がった金属片の「私のマーク・カーソンkaラの場合にnatoストラップのより多くの保安を提供するツールと特徴的なマッチョの観察を提供する。 http://www.bagkakaku.com/vuitton_wallet/wallet/147.html

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 […]
  9. Student Activity: “LATCH Infographics” | LUNACY DESIGNS - […] Location: “Mapping the World’s Biggest Airlines” by James Cheshire […]
  10. Visualising tweeters during the first 10 days of Muharram | deseRt scrolls - […] was also inspired by the work of James Cheshire, seeing which I realised how easy it was to produce …
  11. Steps toward recreating The Facebook IPO plot | NYC Data Science Program - […] the capabilities of ggplot2. In particular, I draw heavily upon the tutorials by FlowingData and Spatial.ly. If you haven’t heard …
  12. Use R to plot flight routes on a fancy world background | Weimin.Wang - […] to me. It demonstrates how powerful R (and ggplot) can be when visualizing data. The original blog, however, does not have codes or …

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=""> <s> <strike> <strong>