我试图摆脱落在我读取的 shapefile 边界之外的空间几何。如果没有像 Photoshop 这样的手动软件,是否可以做到这一点?或者我手动移除跨越城市边界之外的区域。例如,我拿出了 14 张小册子,这是有结果的:

我已经提供了数据的所有子集和自己测试的密钥。代码脚本如下,数据集为https://github.com/THsTestingGround/SO_geoSpatial_crop_Quest。
我st_intersection(gainsville_df$Geomtry$x, gnv_poly$geometry)在转换Geomtry为sf.
library(sf)
library(tigris)
library(tidyverse)
library(tidycensus)
library(readr)
library(data.table)
#reading the shapefile
gnv_poly <- sf::st_read("PATH\\GIS_cgbound\\cgbound.shp") %>%
sf::st_transform(crs = 4326) %>%
sf::st_polygonize() %>%
sf::st_union()
#I have taken the "geometry" of latitude and longitude because it was corrupting my csv, but we can rebuild like so
gnv_latlon <- readr::read_csv("new_dataframe_data.csv") %>%
dplyr::select(ID,
Latitude,
Longitude,
Location) %>%
dplyr::mutate(Location = gsub(x= Location, pattern = "POINT \\(|\\)", replacement = "")) %>% …Run Code Online (Sandbox Code Playgroud) 我使用 绘制了一个空间地图,但是只要参数位于其中,geom_sf它就会不断地为我的参数拾取连续比例,但是当我将其取出并填充时,它也不起作用,它会覆盖我的手动颜色,而图例不会展示。我尝试传入内部层,但这会导致错误:fillaesscale_fill_manualfillaesas.factors
错误:提供给连续刻度的离散值
但这些价值观是谨慎的!所以我必须把它变成数字。new_file.csv可以在此处找到可重现的示例和数据文件:
https://github.com/THsTestingGround/SO_question_fill_map/blob/master/new_file.csv
代码:
options(scipen = 9999,tigris_use_cache = TRUE)
library(sf)
library(tidyverse)
library(tidycensus)
library(RCurl)
library(tigris)
#Took out my census api key because of a feed back from a SO member. Please add a comment
#if you would like my census key.
url <- getURL("https://raw.githubusercontent.com/THsTestingGround/SO_question_fill_map/master/new_file.csv")
#read the csv file
gainsville_df <- read_csv(url) #store the csv file content from my github link
#get the population geomtry shapefiles
alachua <- tidycensus::get_acs(state = …Run Code Online (Sandbox Code Playgroud) 嗨,我不断收到Error: Column column is unknown错误dplyr。我无法修改函数来消除错误。我之所以想做这个函数,是因为我必须对其他变量重复这个过程。
数据可以在这里找到:http ://www.personal.psu.edu/dlp/w540/datasets/titanicsurvival.csv
one_col_count <- function(data, column){
data %>%
group_by(column)%>%
count() %>%
ungroup() %>%
add_row(column= "Total", n= sum(.$n)) -> dataset
return(dataset)
}
survival_count <- one_col_count(dat, as.name("Survived"))
#dat is a data.frame where I changed to types of every column to factor
#Whereas this works
#survival_count <- dat %>%
# group_by(Survived)%>%
# count() %>%
# ungroup() %>%
# add_row(Survived= "Total",
# n= sum(.$n))
#And I get the output
## A tibble: 3 x …Run Code Online (Sandbox Code Playgroud)