2

我正在为湖生成叶绿素图。我想用蓝色填充湖,那里的叶绿素浓度非常低,NA 值为浅蓝色。我正在使用下面给出的代码

gplot(Chlorophyll_map_5) + geom_tile(aes(fill=value)) + scale_fill_gradient(low = 'blue', high = 'red', na.value='blue',name="Chl-a (ug/l)",limits=c(0,1000)) + coord_equal()+theme_bw()

这给了我这样的情节na.value='blue'

na.value='blue'

当我使用时,na.value='transparent'我得到了这个图像:

na.value='transparent'

如果我改变 na.value 的颜色,它也会改变背景。有没有办法在不改变背景的情况下用颜色填充湖?

我的数据的输出:`我的数据的输出:

Formal class 'RasterLayer' [package "raster"] with 12 slots
..@ file    :Formal class '.RasterFile' [package "raster"] with 13 slots
.. .. ..@ name        : chr    "/private/var/folders/68/hm_5ts9x7psb6j3wnb91_bfr0000gn/T/RtmpZ3BLZD/raster/r_tmp_2017-07-18_133827_28365_34843.grd"    
.. .. ..@ datanotation: chr "FLT8S"
.. .. ..@ byteorder   : Named chr "little"
.. .. .. ..- attr(*, "names")= chr "value"
.. .. ..@ nodatavalue : num -1.7e+308
.. .. ..@ NAchanged   : logi FALSE
.. .. ..@ nbands      : int 1
.. .. ..@ bandorder   : Named chr "BIL"
.. .. .. ..- attr(*, "names")= chr "value"
.. .. ..@ offset      : int 0
.. .. ..@ toptobottom : logi TRUE
.. .. ..@ blockrows   : int 0
.. .. ..@ blockcols   : int 0
.. .. ..@ driver      : chr "raster"
.. .. ..@ open        : logi FALSE
..@ data    :Formal class '.SingleLayerData' [package "raster"] with 13 slots
.. .. ..@ values    : logi(0) 
.. .. ..@ offset    : num 0
.. .. ..@ gain      : num 1
.. .. ..@ inmemory  : logi FALSE
.. .. ..@ fromdisk  : logi TRUE
.. .. ..@ isfactor  : logi FALSE
.. .. ..@ attributes: list()
.. .. ..@ haveminmax: logi TRUE
.. .. ..@ min       : num 0.00335
.. .. ..@ max       : num 3870657
.. .. ..@ band      : int 1
.. .. ..@ unit      : chr ""
.. .. ..@ names     : chr "layer"
..@ legend  :Formal class '.RasterLegend' [package "raster"] with 5 slots
.. .. ..@ type      : chr(0) 
.. .. ..@ values    : logi(0) 
.. .. ..@ color     : logi(0) 
.. .. ..@ names     : logi(0) 
.. .. ..@ colortable: logi(0) 
..@ title   : chr(0) 
..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
.. .. ..@ xmin: num 35.8
.. .. ..@ xmax: num 36.7
.. .. ..@ ymin: num 2.4
.. .. ..@ ymax: num 4.65
..@ rotated : logi FALSE
..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
.. .. ..@ geotrans: num(0) 
.. .. ..@ transfun:function ()  
..@ ncols   : int 3240
..@ nrows   : int 8321
..@ crs     :Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+proj=longlat +ellps=WGS84 +no_defs"
..@ history : list()
..@ z       : list()
4

1 回答 1

0
x <- trim(Chlorophyll_map_5)
ggplot(Chlorophyll_map_5) + 
geom_tile(aes(fill=value)) + 
scale_fill_gradient(low = 'blue', high = 'red', na.value='blue',name="Chl-a (ug/l)",limits=c(0,1000)) + 
coord_equal()+theme_bw()

根据文档,该trim函数“通过删除仅包含 NA 值的外部行和列来裁剪 RasterLayer”

于 2017-07-18T13:45:18.850 回答