Keep exploring the things we can do on a map with ggplot2 and ggvis.

The data to be used:

• China map shape file:

• China demographic of 6 censuses:

• The coordinates of province capitals in China:

• The private vehicle ownership per province (source: NBSC, Unit: k; Year: 1998, 2003, 2008, 2013; Hong Kong, Macau & Taiwan excl.):

## Preparation

Load packages and set the language environment:

Load and clean the raw data. Get 2 data frame cnmapdf and cap_coord as we did in the previous visualization article.

As we are going to draw pie and bar chart for each province, we need to add a bit more information to cap_coord.

## Bubbles on A Map

### Bubbles with A Single Color - ggplot2

A bubble can be considered as a point, of which the size is controlled by the car ownership statistics.

### Bubbles with Effect of Heat Map - ggplot2

Calculate the growth rate the private car from 2008 to 2013, assign the data to argument fill of geom_point().

The bubbles with transparency cannot display the difference clearly when the growth rates are similar across provinces. Let’s try smaller bubbles without specifying the transparency. We can also remove the legend to keep the map simple and clear.

It seems that from 2008 to 2013, Hainan and Gansu are the 2 provinces with the quickest growth.

### Bubbles by ggvis

To remove the legend, ggvis provides hide_legend(), within this function, you can specify the names of scales to be hidden.

## Bar Charts on A Map

### Bar Charts by ggplot2

It is more complicated to place a bar chart than plot just a bubble on certain spot.
To locate a bubble, you just need to give aes() the coordinates which have nothing to do with the size and color of bubble.
Regarding bar chart, we need to assign at least 2 pairs of x and y, one for bar chart location and the other for the height and width of the bar chart. In other words, we need to know the coordinates of 4 corners for a bar.

Since a bar chart may takes more space and looks more complicated than a bubble, we just plot 4 cities.

We could add more details, i.e. the avg. growth rate in the from 2003 to 2013.

### Bar Charts by ggvis

It is the same logic to plot by ggvis.

I tried to combine the last 2 layer_text() functions together (the chunk below) and add a “%” to the end of the percentage point but it returns undefined at the position which is supposed to be like Beijing 14.78%. Need to figure out why the function does not support multiple embedding.