我想使用类似于下面的R studio(在Arc Map中创建)制作一个情节
我试过以下代码:
# data processing
library(ggplot2)
# spatial
library(raster)
library(rasterVis)
library(rgdal)
#
test <- raster(paste(datafold,'oregon_masked_tmean_2013_12.tif',sep="")) # read the temperature raster
OR<-readOGR(dsn=ORpath, layer="Oregon_10N") # read the Oregon state boundary shapefile
gplot(test) +
geom_tile(aes(fill=factor(value),alpha=0.8)) +
geom_polygon(data=OR, aes(x=long, y=lat, group=group),
fill=NA,color="grey50", size=1)+
coord_equal()
Run Code Online (Sandbox Code Playgroud)
该代码的输出如下所示:
有几点需要注意.首先,R版本缺少分水岭形状文件.那样就好.
其次,R图中较暗的灰色背景是无数据值.在Arc中,它们不显示,但在R中它们显示为gplot.当我使用光栅包中的"plot"时,它们不显示:
plot(test)
Run Code Online (Sandbox Code Playgroud)
我的问题如下:
要注意,我尝试过很多不同的版本
scale_fill_brewer
scale_fill_manual
scale_fill_gradient
Run Code Online (Sandbox Code Playgroud)
等等,但我得到错误,例如
br <- seq(minValue(test), maxValue(test), len=8)
gplot(test)+
geom_tile(aes(fill=factor(value),alpha=0.8)) +
scale_fill_gradient(breaks = br,labels=sprintf("%.02f", br)) +
geom_polygon(data=OR, aes(x=long, y=lat, group=group),
fill=NA,color="grey50", size=1)+
coord_equal()
Regions defined for each Polygons …Run Code Online (Sandbox Code Playgroud)