0
我有一個美國的柵格地圖具有一定範圍的值,我進口如何繪製柵格地圖上的值?
我要覆蓋的是來自一個CSV文件格式就可以了兩點:dput(droplevels(頭(點, 10))):
points <- structure(list(lat = c(37.423333, 37.423333, 35.896667, 32.834722,
32.834722, 32.834722, 32.834722, 32.834722, 32.834722, 32.834722
), lon = c(-122.188333, -122.188333, -121.087222, -116.622222,
-116.622222, -116.622222, -116.622222, -116.622222, -116.622222,
-116.622222)), .Names = c("lat", "lon"), row.names = c(NA, 10L
), class = "data.frame")
等
我想fortify(prcp)
但導致這一錯誤:
Error: ggplot2 doesn't know how to deal with data of class RasterLayer
我該怎麼辦?
TRY:
library(raster)
library(sp)
coordinates(points) = ~lon+lat
proj4string(points) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
r <- getData("worldclim",var="bio",res=10)
r<-r[[12]] #Annual Precipitation
names(r) <- c("Prec")
r <- crop(r, extent(-130, -60, 20, 60))
spplot(r) + layer(panel.points(x, y, col="green", cex=0.1, pch=1), data=points)
但輸出全部爲綠色不知何故,即使點應該只有9000點。
怎麼樣[這](https://gis.stackexchange.com/questions/175108/add-a-point- on-a-spplot-in-r)解決方案? – Lyngbakr
@Lyngbakr我嘗試過,但我得到所有的綠色,而不是點。我究竟做錯了什麼? – maximusdooku