- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用库 Tmap 在 R 的国家 map 上绘制学区。我使用了 official website 中的 shapefile , 国家教育统计中心,用于学区边界。请注意,我使用的是 2019 文件而不是最新文件,您可以从前面提到的链接中的 Single Composite File 下载此文件。我首先尝试了一个州,犹他州,一切顺利,没有任何问题。我绘制这张 map 的代码和国家 map (from Bloomberg Citylab) 的引用如下;
library (sf)
library (tmap)
map <- st_read(".../schooldistrict_sy1819_tl19.shp")
ut <- map[map$STATEFP == 49, ]
tm_shape(ut) + tm_borders()
但是我在尝试制作国家 map 的时候遇到了错误。我使用此代码并收到以下错误。
tm_shape(map) + tm_borders()
Error: Shape contains invalid polygons. Please fix it or set tmap_options(check.and.fix = TRUE) and rerun the plot
当然,我做了一些研究。一个网站建议由于无效的几何图形而发生以下错误。我检查并试图使这些有效,但我犯了和第一次一样的错误。我试图用以下代码解决这个问题。
sum(!st_is_valid(map$geometry))
[1] 858
st_make_valid(map$geometry)
Geometry set for 13315 features
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -179.1686 ymin: -14.5487 xmax: 179.7487 ymax: 71.38961
Geodetic CRS: NAD83
First 5 geometries:
MULTIPOLYGON (((-80.11417 26.07902, -80.11423 2...
MULTIPOLYGON (((-82.19919 26.77353, -82.19748 2...
MULTIPOLYGON (((-81.45356 25.80323, -81.45388 2...
MULTIPOLYGON (((-80.39962 25.25725, -80.40002 2...
MULTIPOLYGON (((-81.56409 27.34066, -81.56423 2...
tm_shape(map) + tm_borders()
Error: Shape contains invalid polygons. Please fix it or set tmap_options(check.and.fix = TRUE) and rerun the plot
由于我对 R 中的几何结构一无所知,所以我完全不知道如何让它发挥作用。如果以前有人这样做过,您能否就此分享任何意见/建议?解决此问题的任何想法将不胜感激。非常感谢您阅读我的问题!
最佳答案
感谢@mrhellmann,他发现了我犯的小错误,您需要在使用st_make_valid
后将 map 数据分配给新变量。我使用以下代码将区级数据绘制到全国 map 中。
library (SF)
library (tmap)
map <- st_read(".../schooldistrict_sy1819_tl19.shp")
map2 <- st_make_valid(map$geometry)
tm_shape(map2) + tm_borders()
关于r - Tmap:无法创建国家级学区 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71743028/
是否可以在 tmap 创建的 map 上包含多个 tm_compass()? 我知道您可能不太需要,但假设您想展示不同的指南针类型。使用 spData 包中的 nz 我尝试将每个新指南针添加为附加层,
有没有办法动态防止 tmap 中图例中的重叠值? 拿这个例子: library(tmap) data("World") tm_shape(World) + tm_polygons("HPI", n=7
我正在尝试创建一个函数来映射特定州学区的不同变量。但是我在格式化图例时遇到了一些问题。目前我已经列出了适合 map 的最佳方式(水平),但一些文本被切断(低于平均贫困率),我想在图例中的数字标签中添加
我正在尝试创建一个函数来映射特定州学区的不同变量。但是我在格式化图例时遇到了一些问题。目前我已经列出了适合 map 的最佳方式(水平),但一些文本被切断(低于平均贫困率),我想在图例中的数字标签中添加
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。
我正在使用 tMap 组件。我有一个默认模式为“dd-MM-yyyy”的日期字段。我只需要插入一个空白值。我试过 '01-01-1900',"",TalendDate.getCurrentDate()
我想使用库 Tmap 在 R 的国家 map 上绘制学区。我使用了 official website 中的 shapefile , 国家教育统计中心,用于学区边界。请注意,我使用的是 2019 文件而
当栅格中只有一个值时,我想调整用 tmap 绘制的栅格的基本颜色。 这是一个非常简单的可重现示例: library(raster) library(tmap) a <- raster(matrix(s
第一次在 stackoverflow 上发帖。我一直在学习使用 tmap,并且已经为我需要的等值线图获取了几乎所有内容。然而,我似乎无法找到答案的画龙点睛是让图例标题比下面的文字更大。也想让它变得大胆
我做了一张 map unsing tmap使用 leaflet 包含在 Shiny 的应用程序中.我大致有我想要的:基于 SpatialPolygonsDataFrame 的带有填充颜色的专题 map
我想用 tmap 包在密度图中绘制 1950 年的世界人口。 我手动将人口数据分成 22 个类别,并为每个类别填充不同的颜色。 我的代码是: library(tmap) data(Wo
我正在尝试在 tmap 图中添加一些文本标签。 library(tmap) library(raster) jnk <- getData("GADM",country="IND",level=2) m
我是编程新手,目前正在参加使用 R 的介绍性空间分析类(class)。以下代码生成下面包含的 tmap。 如何将每个 tmap 的标题居中,并将图例放置在右上角而不将 map 本身放在上面? 非常感谢
我有一张使用 tmap 库生成的拥挤 map ,我在 中使用参数 legend.show = FALSE 关闭了图例>tm_layout() 函数。 我想知道的是:有没有办法自己为这张 map 生成图
我不确定如何或是否可以通过以下方式调整关键图例。考虑这个例子: library(tmap) data(Europe) my_map % st_as_sf() %>% # from sf pack
我有这个代码: tm_shape(usa, bbox = bbox, projection = map.crs)+ tm_borders(col = "grey", lwd = 1) + tm
我有一张使用 tmap 库生成的拥挤 map ,我在 中使用参数 legend.show = FALSE 关闭了图例>tm_layout() 函数。 我想知道的是:有没有办法自己为这张 map 生成图
我有一个 TALEND ETL 作业,我正在尝试稍微修改它。 在其中一个 tMap 中,我有一个如下所示的表达式: row.regulation.equals("Reg200806.s3.2a") |
我有这个代码: tm_shape(usa, bbox = bbox, projection = map.crs)+ tm_borders(col = "grey", lwd = 1) + tm
我正在使用 Talend 来准备数据件。 我想使用 tMap 组件将字符串与列的内容进行比较,并创建一个变量以存储在数据库中。问题在于==运算符没有给出正确的结果(例如: row2.recipient
我是一名优秀的程序员,十分优秀!