为tm_fill创建调色板

时间:2017-10-03 18:05:09

标签: r colors palette choropleth tmap

我正在尝试创建一个颜色调色板,我可以在tm_fill函数中使用它,以便能够创建一个等值区域图。

POJO1 pojo = buildPOJO();
POJO2 pojo = buildPOJO(); // Same method to build both pojo's

目前我正在使用预设的调色板,但我想知道是否有办法创建自己的自定义调色板,然后将其替换为tm_shape(LdnCensusMap) + tm_borders(col = 'Grey', alpha = 0.3) + tm_fill(col = "Privaterent", palette = sequential_hcl(8, alpha=0.6), title = "Privately Rented (%)", style = "equal", n = 8,) + tm_shape(ldn) +

非常感谢

1 个答案:

答案 0 :(得分:3)

您正在使用套餐tmaps,对吗?您可以使用RColorBrewer创建调色板,就像他们在此示例中所做的那样(在包的文档中):

data(World, Europe, NLD_muni, NLD_prov, land, metro)

if (require(RColorBrewer)) {
pal <- brewer.pal(10, "Set3")[c(10, 8, 4, 5)]
tm_shape(Europe) +
tm_polygons("EU_Schengen", palette=pal, title = "European Countries", 
showNA=FALSE) +
tm_format_Europe()
}

您还可以选择HEX格式的颜色并设置如下调色板:

# Random colors in HEX. 
Mypal <- c('#313695','#fee090','#d73027','#72001a')

# Ploting the ma again with my custom palette
tm_shape(Europe) +
tm_polygons("EU_Schengen", palette=Mypal, title = "European Countries", 
showNA=FALSE) +
tm_format_Europe()