R tmap绘制需要很长时间

时间:2019-11-13 10:01:35

标签: r tmap

我正在尝试使用tmap tm_shape()在R中绘制一些多边形,但是当我运行代码时,它只是挂了几个小时。我还无法运行脚本到最后。当我使用内置的plot()绘制多边形时,它会在几秒钟内加载。我对R还是很陌生,所以很容易出现noob错误。请在下面查看我的代码:

setwd("C:/Users/<me>/Desktop/OneDrive/Documents/Geospatial_Science/datas/NY_airbb")

library(tmap)
library(tmaptools)
library(ggplot2)
library(rgdal)
library(sf)
library(raster)

data <- read.csv("AB_NYC_2019.csv")
bb_data<-data.frame(data)

tracts<-read_sf(dsn="census_tracts/geo_export_93b6be76-f1d1-4f6c-b45c-7a6e7019a578.shp", 
                layer="geo_export_93b6be76-f1d1-4f6c-b45c-7a6e7019a578")

# specify the geometry columns
xy<-data[,c(8,7)]

# create spatial data frame for the data
bb_data<-SpatialPointsDataFrame(coords=xy, data=bb_data,
                                proj4string=CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))


tracts<-as(tracts, 'Spatial')
# Make same crs
tracts<-spTransform(tracts, CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))

# Get points within each tract
res<-over(bb_data, tracts)
# Make that into count table dataframe
res<-as.data.frame(table(res$ct2010))
colnames(res)[1]<-"ct2010"


# Merge 
bb_tracts<-merge(tracts, res, by="ct2010")

tmap_mode("plot")

tm_shape(bb_tracts, projection=4326, unit='mi')+
  tm_polygons(title="BB frequency\n(Jenks)", col="Freq", style="jenks")
  tm_legend(legend.position = c("right", "bottom"), legend.title.size=1.2)

非常感谢

0 个答案:

没有答案