1

我想在伦敦地图上绘制一些数据。

但是每当我尝试运行以下代码时:

library("Hmisc")
library("lubridate")
library("maptools")
require("rworldmap")

mtl <- readShapePoly('borough/London_Borough_Excluding_MHW.shp')

data = read.csv("test.csv")
data = data[,c("Accident_Index","Longitude","Latitude","Date")]

data$Date <- as.character(data$Date)
data$Date <- gsub(' ', '', data$Date)
data$Date <- dmy(data$Date, tz='UTC')

start <- (dmy("01/01/2011", tz='UTC'))
days <- start

# pre processed matrix for incidents
# trust me you don't want to calculate
# this from scratch (Takes hours)
load('time_mat.Rdata')

# plot initial world map
plot(getMap())

da <- 1

# where the plots will be outputted
png(paste('plots/',days[da],'.png',sep=''), height=800, width=1200, bg='grey')

# plot london map
plot(mtl,col='darkgrey')
text(51.5072, 0.1275,paste("Collisions in London\n",days[da]),cex=2)

points(data$Longitude,data$Latitude, pch=20, col='white', cex=2)

par(lwd=2.5,cex=1.4)

subplot(
  plot(days[1:da],incident_rate[1:da],
    lwd=1.5,type='l',
    ylab='', xlab='',
    col='red',
    ylim=c(0,max(c(1,max(incident_rate[1:da]))))
  ),  
  size=c(5.5,2), 51.5072, -0.1275, vadj=0,hadj=0
)

dev.off()

par(plt = c(xy$x, xy$y), new = TRUE) 中的错误:为图形参数“plt”指定的值无效

编辑 2:重构并减少代码。

压缩了整个代码文件夹和依赖数据以便于部署/测试,最终压缩了约 17mb(由于 shapefile):

大文件上传链接

4

0 回答 0