Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Scatter Plots > Creating a Balloon Plot

Creating a Balloon Plot

Problem

You want to make a balloon plot, where the area of the dots is proportional to their numerical value.

Solution

Use geom_point() with scale_size_area(). For this example, we’ll use a subset of the countries data set:

library(gcookbook) # For the data set

cdat <- subset(countries, Year==2009 &
    Name %in% c("Canada", "Ireland", "United Kingdom", "United States",
                "New Zealand", "Iceland", "Japan", "Luxembourg",
                "Netherlands", "Switzerland"))

cdat

           Name Code Year       GDP laborrate healthexp infmortality
         Canada  CAN 2009  39599.04      67.8  4379.761          5.2
        Iceland  ISL 2009  37972.24      77.5  3130.391          1.7
        Ireland  IRL 2009  49737.93      63.6  4951.845          3.4
          Japan  JPN 2009  39456.44      59.5  3321.466          2.4
     Luxembourg  LUX 2009 106252.24      55.5  8182.855          2.2
    Netherlands  NLD 2009  48068.35      66.1  5163.740          3.8
    New Zealand  NZL 2009  29352.45      68.6  2633.625          4.9
    Switzerland  CHE 2009  63524.65      66.9  7140.729          4.1
 United Kingdom  GBR 2009  35163.41      62.2  3285.050          4.7
  United States  USA 2009  45744.56      65.0  7410.163          6.6

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint