我一直在阅读文档,但没有找到这个问题。
我有一个包含三列的数据框。前两个是gps坐标,[如(省,马萨诸塞州,美国)为42.06,-70.19],第三列是每个坐标的值。
该数据框称为aes()
这是我到目前为止所拥有的:
forRaster
但是library(raster)
library(leaflet)
library(rgdal)
needsRaster = rasterFromXYZ(forRaster)
plot(needsRaster)
needsImage = image(needsRaster)
needsLeafletRaster = projectRasterForLeaflet(needsImage)
needsMap = leaflet()
addRasterImage(needsMap, needsLeafletRaster)
needsMap
电话后我一直收到此错误:
projectRasterForLeaflet
我发现传单文档并不完全是直截了当的,我想知道是否有人来帮忙。如果我需要以任何方式使光栅不同,我很乐意这样做。感谢。
答案 0 :(得分:0)
我明白了!
# Made a new data frame with lat, long, and the value
df = data.frame(value = v, lng = y, lat = x)
#Did this....
s = SpatialPixelsDataFrame(df[,c('lng', 'lat')], data = df)
crs(s) = sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
r = raster(s)
# Set up the colors
val = as.numeric(c(0:max(df$value)))
pal = colorNumeric(c("yellow", "orange", "red"), val,
na.color = "transparent")
# Made the map
leaflet() %>% addProviderTiles("CartoDB.Positron") %>%
addRasterImage(r, colors = pal, opacity = 0.5) %>%
addLegend(pal = pal, values = val, title = "Number of Needs")