微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R:为什么我的数据在我用传单制作的 choropleth 中没有对齐?

如何解决R:为什么我的数据在我用传单制作的 choropleth 中没有对齐?

我正在使用来自奥卢地区的开放数据来预测队列,以便在等值区看到护士。传单将来自 json 文件的线数据很好地覆盖在地图顶部。当我添加要在地图上显示的信息时,数据会转到错误的区域。我认为这与坐标系和与 shapefile 的对齐有关,但我不知道该怎么做。

当我从其源中提取数据时,我将在这里提供我已经需要的所有库:

结果是这样的: Map where the colors of queues mismatch with the regions seen in the data frame mean_oulu

Here is image of data frame mean_oulu where the values are with right regions

我怎样才能让区域在 choropleth 中以正确的阴影着色,以便它们对应于 mean_oulu$mean_nurse_queue 值?

library(ggplot2)
library(ggmap)
library(leaflet)
library(geojsonio)
library(rgdal)
library(sf)
library(dplyr)
library(raster)
library("rjson")
library("sf")
library("geojsonR")
library("geojsonio")
library("shiny")
library("leaflet")
library("digest")

##Healthcare center coordinates from: https://www.avoindata.fi/data/en_GB/dataset/oulun-kaupungin-terveysasemien-ja-hyvinvointikeskusten-kiireettomien-aikojen-jonotilanne
data2 <- "Hyvinvointikeskukset_ja_pisteet.geojson"
data_json <- geojson_read(data2,what = "sp")
plot(data_json)
data_json_df <- fortify(as.data.frame(data_json))
#Checked the crs: +proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs
crs(data_json)
#Shapefile was downloaded from https://data.ouka.fi/data/dataset/oulun-suuraluejako "Oulun suuraluejako 2018"
##Shapefile apparently uses coordinates epsg 3133
oulu_suuralueet <- readOGR("C:/Users/katri/Documents/suuralueet_2018a/suuralueet_2018a.shp")
#checked the crs: +proj=tmerc +lat_0=0 +lon_0=26 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs
crs(oulu_suuralueet)

#Data to be used
mean_dr_queue <- c(35.257273,33.60000,26.0000,25.45455,27.72727,39.45455,32.22222,31.20000,32.09091)
mean_nurse_queue <- c(34.45455,28.50000,18.81818,19.18182,24.45455,20.18182,16.33333,21.700000,10.18182)
regions <- c("Oulunsuu","Kaakkuri","Tuira","Pateniemi","Kaijonharju","Myllyoja","Kiiminki","Oulunsalo","Haukipudas")
lon <- c(25.5279,25.5284,25.4708,25.4090,25.4807,25.5514,25.7757,25.4140,25.3532)
lat <- c(65.0088,64.9693,65.0260,65.0793,65.0599,65.0195,65.1281,64.9347,65.1763)
mean_oulu <- data.frame(mean_dr_queue,mean_nurse_queue,regions,lon,lat)

#This CRS was set because it was the only way to get the region lines projected on the map
regions_oulu <- spTransform(oulu_suuralueet,CRS("+proj=longlat +datum=wgs84"))


#Graphics
asteikko <- c(10,15,20,25,30,35)
pal2 <-  colorBin("Blues",domain = mean_oulu$mean_nurse_queue,bins = asteikko,pretty =FALSE)

#Make the map
mymap <- leaflet() %>%
  setView(lng = 25.4681600,lat = 65.0123600,zoom = 12) %>%
  addTiles() %>%
  addpolygons(data = suuralueet_aineisto,weight = 1,smoothFactor = 0.5,fillOpacity = 0.8,fillColor = ~pal2(as.numeric(mean_nurse_queue))) %>%
  addCircleMarkers(lng = mean_oulu$lon,lat = mean_oulu$lat,label = mean_oulu$regions) %>%
  addLegend(pal = pal2,values = mean_oulu$mean_nurse_queue,position = "bottomright",title = "Mean nurse queue")
mymap ```

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。