R中的等值统计图
choroplethr maps in R
又一个关于等值线图的问题来了。首先让我们做一些数据。
`a<-c(4.1,2.5,0.4,6.4,1.4,1.8,3.8,1.3,2.3,8.4,5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,4.0,1.3,4.8,2.6,2.8,2.3,3.1,2.5)
target<-c("austria","belgium","bulgaria","switzerland","cyprus","czech republic","denmark",
"estonia","spain","finland","france","greece","croatia","hungary","ireland","italy",
"lithuania","luxembourg","latvia","norway","poland","portugal","romania","sweden",
"slovenia","slovakia","turkey","united kingdom")
datas<-data.frame(region=target,value=a)
datas$region<-as.character(datas$region)
install.packages("choroplethr")
install.packages("choroplethrMaps")
library(choroplethr)
library(choroplethrMaps)
data(country.map)
data(country.regions)
gg <- country_choropleth(datas,legend="%",num_colors=1,zoom=target)
gg <- gg + xlim(-31.266001, 39.869301)
gg <- gg + ylim(27.636311, 81.008797)
gg <- gg + coord_map("lambert", lat0=27.636311, lat1=81.008797)
gg`
所以输出是
我不能调整的是让一个国家保持原样。如果我将一个国家的值设置为等于 0 ,那将大大改变其他国家的颜色比例。我的目标是在地图中添加我没有数据的国家,并将它们的颜色设置为灰色,使地图更逼真,并指出我有数据的国家。
我认为这里有两点。
默认情况下,choroplethr 中的所有 NA 值都呈现为黑色:
a <- c(NA, NA, NA,6.4,1.4,1.8,3.8,1.3,2.3,8.4,
5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,
4.0, 1.3,4.8,2.6,2.8,2.3,3.1,2.5)
...
请注意,您可以通过以下方式覆盖比例:
gg + scale_fill_continuous(low="#eff3ff", high="#084594", na.value="yellow")
您说过您希望 NA 值显示为灰色。您也可以通过更改 na.value
的值来做到这一点。这里我选择黄色只是为了对比大,因为这是一个例子。
又一个关于等值线图的问题来了。首先让我们做一些数据。
`a<-c(4.1,2.5,0.4,6.4,1.4,1.8,3.8,1.3,2.3,8.4,5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,4.0,1.3,4.8,2.6,2.8,2.3,3.1,2.5)
target<-c("austria","belgium","bulgaria","switzerland","cyprus","czech republic","denmark",
"estonia","spain","finland","france","greece","croatia","hungary","ireland","italy",
"lithuania","luxembourg","latvia","norway","poland","portugal","romania","sweden",
"slovenia","slovakia","turkey","united kingdom")
datas<-data.frame(region=target,value=a)
datas$region<-as.character(datas$region)
install.packages("choroplethr")
install.packages("choroplethrMaps")
library(choroplethr)
library(choroplethrMaps)
data(country.map)
data(country.regions)
gg <- country_choropleth(datas,legend="%",num_colors=1,zoom=target)
gg <- gg + xlim(-31.266001, 39.869301)
gg <- gg + ylim(27.636311, 81.008797)
gg <- gg + coord_map("lambert", lat0=27.636311, lat1=81.008797)
gg`
所以输出是
我不能调整的是让一个国家保持原样。如果我将一个国家的值设置为等于 0 ,那将大大改变其他国家的颜色比例。我的目标是在地图中添加我没有数据的国家,并将它们的颜色设置为灰色,使地图更逼真,并指出我有数据的国家。
我认为这里有两点。
默认情况下,choroplethr 中的所有 NA 值都呈现为黑色:
a <- c(NA, NA, NA,6.4,1.4,1.8,3.8,1.3,2.3,8.4, 5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8, 4.0, 1.3,4.8,2.6,2.8,2.3,3.1,2.5) ...
请注意,您可以通过以下方式覆盖比例:
gg + scale_fill_continuous(low="#eff3ff", high="#084594", na.value="yellow")
您说过您希望 NA 值显示为灰色。您也可以通过更改 na.value
的值来做到这一点。这里我选择黄色只是为了对比大,因为这是一个例子。