Keep the visualization study, try to realize the following tasks:
- Plot one province or multiple provinces
- Add labels to capitals
- Plot the provincial population based on the latest census
- Plot the provincial population evoluation
- Realize the plots above using both
Load packages and modify local settings in case of Chinese characters not displaying.
Subset the polygons with
AREA larger than 0.005 and remove the
cnmapdf which contains
prov_cn and key map plotting info:
You can also use
dplyr to realize the last step, but it is much slower.
Set the capital coordinates of each provinces.
Let’s try to plot Shanghai first.
To plot a group of provinces, say Jiangsu, Zhejiang and Shanghai, the Yangtze River Delta.
Why do we declare
geom_polygon() instead of
ggplot()? Run the code below and try to move it to the aesthetic mapping in
ggplot() and you will find the answer.
It’s apparently a bit complicated using
annotate() to add labels to provinces. We can do that this way:
How can we do that via
In the current version (0.4.2) there is no function like
ggplot2::ggtitle() to directly add a title to a
ggvis package. So we can define one ourselves.
add_title() to our plot
Macau is not specified in the raw data, therefore we only plot the other 33 provinces / municipalities / autonomous regions.
Population data is scrapped from Wikipedia based on Census. The population Hong Kong and Taiwan are independently collected, so I pick the data in the most adjacent years.
You could download the
.xlsx raw data DemoChinaRaw.xlsx and the
.csv cleaned data DemoChina.csv.
Need to pay attention to the changes of provinces:
- Chongqing was a city of Sichuan Province and became a municipality in 1997.
- Hainan was a part of Guangdong Province and became an independent province in 1988. This is not reflected in the result of Census in 1990).
- From 1949 to now, Tianjin is a municipality but once was a city of Hebei Province between 1958 and 1967.
Combine the population from Census in 2010 with map data:
To make the heat map by another color scale:
To check the population evolution per each census by
Based on the census in 1982 and 1990, the population in Sichuan Province is even higher than in the following years. Should be aware that before the census in 2000, Chongqing is a city of Sichuan. That is how the illusion comes.
It is a shame that
ggvis cannot do faceting yet.