r 用颜色按百分比填充地图

罗伯特

如何按国家面积的百分比用颜色填充地图图。

例子 在此处输入图片说明

library(sp)
library(raster)


# https://gadm.org/download_country_v3.html level-0
ger.shape <- readRDS("gadm36_DEU_0_sp.rds")
plot(ger.shape, col = 'lightgrey', border = 'darkgrey')
raster(extent(ger.shape))
斯图尔特麦克唐纳

这可能是一种非常低效的方法,但这是一个开始:

library(sf)

# increment in metres.
# Smaller numbers will give you a more accurate map, but will take longer to calculate
increment <- 10*1000

# load shapefile and convert to an equal-area projection so we can work in metres
gerShp <- st_read('gadm36_DEU_shp/gadm36_DEU_0.shp') # change this to the correct path
gerShp <- st_transform(gerShp, 3035)

# calculate total area and our 30% value
totalArea <- st_area(gerShp)
thirtyPC <- totalArea * 0.3

# Plot it
plot(gerShp, col = 'lightgrey', border = 'darkgrey', max.plot=1, reset=F)

# Find the bounding box of the feature
bbox <- st_bbox(gerShp)

thisArea <- totalArea - totalArea # zero with correct units
i <- 1

# While our subarea is less than 30%...
while (thisArea < thirtyPC) {

    # Starting at bottom, create a bounding box that is smaller than full bounding box
    thisBBox <- bbox
    thisBBox['ymax'] <- thisBBox$ymin + (increment * i)

    # Clip shp to this bounding box
    thisSubarea <- st_crop(gerShp, y=thisBBox)
    thisArea <- st_area(thisSubarea)

    print(thisArea)

    i <- i + 1

}

plot(thisSubarea, max.plot=1, add=T, col='red', border=NA)
actualPercentage <- thisArea / totalArea

实际百分比 = 0.3011579

图像

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

确定R中的字符匹配百分比

来自分类Dev

根据百分比用渐变颜色填充圆环。

来自分类Dev

使表格显示百分比而不是R中的频率

来自分类Dev

按R中的子组百分比汇总

来自分类Dev

R:删除缺少某些百分比值的列

来自分类Dev

如何计算R中的重叠百分比

来自分类Dev

与geom_line的R连续百分比与分类百分比份额

来自分类Dev

在R中按组给出百分比

来自分类Dev

R-按模式和目标计算模式和百分比

来自分类Dev

R中的绘图百分比

来自分类Dev

如何str_extract R中的百分比?

来自分类Dev

如何对R中的百分比进行拆分

来自分类Dev

R xts计算多个系列的百分比指数

来自分类Dev

R中的ddply变换(百分比变化)

来自分类Dev

R中的汇总,以按组计算总计的百分比?

来自分类Dev

在R中按组查找超出百分比?

来自分类Dev

带百分比的R ggplot

来自分类Dev

使用R中的read.table按日期细分百分比数据

来自分类Dev

r中值的百分比变化

来自分类Dev

用R分组并计数发生频率百分比

来自分类Dev

如何使用R计算按选项的响应百分比?

来自分类Dev

R中的按百分比分组与Excel不同

来自分类Dev

用R数据框中的NA随机替换每组值的百分比

来自分类Dev

在R中按类别计算百分比

来自分类Dev

sankey /冲积图,其中百分比和部分填充为R

来自分类Dev

在R中按组汇总百分比

来自分类Dev

在R中按组给出百分比

来自分类Dev

R-按模式和目标计算模式和百分比

来自分类Dev

按R中的百分比增量查找累积数