如何从Choroplethr映射中删除状态缩写
我正在使用一个如何从Choroplethr映射中删除状态缩写,r,ggplot2,maps,choroplethr,R,Ggplot2,Maps,Choroplethr,我正在使用一个choroplethr地图,如下所示。如何简单地删除州缩写 以下是复制代码: library(choroplethr) library(choroplethrMaps) data(df_pop_state) df_pop_state$value <- as.numeric(df_pop_state$value) state_choropleth(df_pop_state, num_colors = 1, titl
choroplethr
地图,如下所示。如何简单地删除州缩写
以下是复制代码:
library(choroplethr)
library(choroplethrMaps)
data(df_pop_state)
df_pop_state$value <- as.numeric(df_pop_state$value)
state_choropleth(df_pop_state, num_colors = 1,
title = "2012 State Population Estimates",
legend = "Population")
库(choroplethr)
图书馆(choroplethrMaps)
数据(df_pop_状态)
df_pop_state$value此函数返回一个ggplot对象,因此您可以手动检查图层并删除不需要的图层(此处您要删除GeomText图层):
声明感谢您使用choroplethr。请注意,Choroplethr使用R6对象。事实上,state\u choropleth
函数只是statechropleth
R6对象的一个方便包装器:
> state_choropleth
function (df, title = "", legend = "", num_colors = 7, zoom = NULL,
reference_map = FALSE)
{
c = StateChoropleth$new(df)
c$title = title
c$legend = legend
c$set_num_colors(num_colors)
c$set_zoom(zoom)
if (reference_map) {
if (is.null(zoom)) {
stop("Reference maps do not currently work with maps that have insets, such as maps of the 50 US States.")
}
c$render_with_reference_map()
}
else {
c$render()
}
}
<bytecode: 0x7fdda6aa3a10>
<environment: namespace:choroplethr>
我选择这种方法是因为,一般来说,我发现R中的许多函数都有大量的参数,这可能会令人困惑。缺点是函数比对象更容易编写文档(特别是在R中),因此经常会出现类似这样的问题
> state_choropleth
function (df, title = "", legend = "", num_colors = 7, zoom = NULL,
reference_map = FALSE)
{
c = StateChoropleth$new(df)
c$title = title
c$legend = legend
c$set_num_colors(num_colors)
c$set_zoom(zoom)
if (reference_map) {
if (is.null(zoom)) {
stop("Reference maps do not currently work with maps that have insets, such as maps of the 50 US States.")
}
c$render_with_reference_map()
}
else {
c$render()
}
}
<bytecode: 0x7fdda6aa3a10>
<environment: namespace:choroplethr>
c = StateChoropleth$new(df_pop_state)
c$title = "2012 State Population Estimates"
c$legend = "Population"
c$set_num_colors(1)
c$show_labels = FALSE
c$render()