使用 AmCharts + R 绘制中国地图

使用 AmCharts + R 绘制中国地图

下午闲着无事写的一个绘制中国地图的 R 包。mapbrew。是个基于 htmlwidgets 的包。amCharts 是一个 JavaScript 图表库。我是基于 amCharts3 编写的这个 R 包。动态图表浏览可以参考该包的文档网站:使用 amCharts + R 绘制中国地图

安装

R
1
devtools::install_github('czxa/mapbrew')

绘制中国地图

R
1
2
3
4
5
6
7
8
9
10
11
library(motherland)
library(mapbrew)
library(magrittr)
df <- motherland::chinadf %>%
dplyr::filter(region == "中国")
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
theme = "dark",
width = "100%")

更改主题

首先是默认主题:

R
1
2
3
4
5
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%")

light 主题:

R
1
2
3
4
5
6
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%",
theme = "light")

chalk 主题:

R
1
2
3
4
5
6
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%",
theme = "chalk")

dark 主题:

R
1
2
3
4
5
6
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%",
theme = "dark")

black 主题:

R
1
2
3
4
5
6
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%",
theme = "black")

colorSteps:图例中颜色的分层数量

R
1
2
3
4
5
6
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
width = "100%",
colorSteps = 5)

smallMap:添加小地图

R
1
2
3
4
5
6
7
8
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 1,
smallMapTop = 160,
smallMapRight = 10,
width = "100%",
colorSteps = 5)

valueLegendBottom / valueLegendRight:图例的位置

R
1
2
3
4
5
6
7
8
cnmap(id = df$name,
value = df$value,
description = paste0(df$name, ": ", df$value, "人"),
smallMap = 0,
valueLegendBottom = 40,
valueLegendRight = 350,
width = "100%",
colorSteps = 5)

其它

R
1
?mapbrew::cnmap()
# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×