Instruction

Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity!

https://plot.ly/r/bubble-maps/

library(plotly)
# Major cities in China
# Data source: https://simplemaps.com/data/cn-cities
cn_cities <- read.csv("D:/R/data/cn_cities.csv", 
  header=TRUE, 
  #colClasses="character",
  strip.white=FALSE,
  stringsAsFactors=FALSE, 
  na.strings=c("NA", "NaN", "N/A", "", "#VALUE!", "#DIV/0!"),
  encoding='UTF-8')
dim(cn_cities)
## [1] 2187    9
str(cn_cities)
## 'data.frame':    2187 obs. of  9 variables:
##  $ city             : chr  "Shanghai" "Beijing" "Guangzhou" "Shenzhen" ...
##  $ lat              : num  31.2 39.9 23.1 22.5 30.6 ...
##  $ lng              : num  121 116 113 114 114 ...
##  $ country          : chr  "China" "China" "China" "China" ...
##  $ iso2             : chr  "CN" "CN" "CN" "CN" ...
##  $ admin            : chr  "Shanghai" "Beijing" "Guangdong" "Guangdong" ...
##  $ capital          : chr  "admin" "primary" "admin" "minor" ...
##  $ population       : int  14987000 11106000 8829000 7581000 7243000 7180000 6461000 4787000 4528000 4123000 ...
##  $ population_proper: int  14608512 7480601 3152825 1002592 4184206 3766207 3967028 3512192 4528000 3950437 ...
# The top 50 largest cities in China by population
cities <- cn_cities[order(-cn_cities$population),]; head(cities)
##        city      lat      lng country iso2     admin capital population
## 1  Shanghai 31.22222 121.4581   China   CN  Shanghai   admin   14987000
## 2   Beijing 39.92882 116.3889   China   CN   Beijing primary   11106000
## 3 Guangzhou 23.11667 113.2500   China   CN Guangdong   admin    8829000
## 4  Shenzhen 22.53333 114.1333   China   CN Guangdong   minor    7581000
## 5     Wuhan 30.58333 114.2667   China   CN     Hubei   admin    7243000
## 6   Tianjin 39.14222 117.1767   China   CN   Tianjin   admin    7180000
##   population_proper
## 1          14608512
## 2           7480601
## 3           3152825
## 4           1002592
## 5           4184206
## 6           3766207
cities <- cities[c(1:50),]
cities <- data.frame(city=cities$city, pop=cities$population,
  lat=cities$lat, lng=cities$lng)
geo <- list(
  scope = 'asia',
  projection = list(type = 'Mercator'),
  showland = TRUE,
  landcolor = toRGB("gray85"),
  countrycolor = toRGB("white"),
  subunitcolor = toRGB("white"),
  subunitwidth = 1,
  countrywidth = 1
)

plot_geo(cities, locationmode = 'CHN', sizes = c(1, 200)) %>% 
  add_markers(x = ~lng, y = ~lat, size = ~sqrt(pop),
              hoverinfo = "text", text = ~paste(city, "<br />", pop)) %>%
  layout(title = 'Top 50 Largest Cities by Population in China', geo = geo)