2017-07-18 27 views
1

我正在生成湖泊葉綠素圖。我想用藍色填充湖泊,其中葉綠素濃度非常低,NA值爲淡藍色。我使用的是下面的代碼如何區分gplot中的背景顏色和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 
[email protected] file :Formal class '.RasterFile' [package "raster"] with 13 slots 
.. .. [email protected] name  : chr "/private/var/folders/68/hm_5ts9x7psb6j3wnb91_bfr0000gn/T/RtmpZ3BLZD/raster/r_tmp_2017-07-18_133827_28365_34843.grd"  
.. .. [email protected] datanotation: chr "FLT8S" 
.. .. [email protected] byteorder : Named chr "little" 
.. .. .. ..- attr(*, "names")= chr "value" 
.. .. [email protected] nodatavalue : num -1.7e+308 
.. .. [email protected] NAchanged : logi FALSE 
.. .. [email protected] nbands  : int 1 
.. .. [email protected] bandorder : Named chr "BIL" 
.. .. .. ..- attr(*, "names")= chr "value" 
.. .. [email protected] offset  : int 0 
.. .. [email protected] toptobottom : logi TRUE 
.. .. [email protected] blockrows : int 0 
.. .. [email protected] blockcols : int 0 
.. .. [email protected] driver  : chr "raster" 
.. .. [email protected] open  : logi FALSE 
[email protected] data :Formal class '.SingleLayerData' [package "raster"] with 13 slots 
.. .. [email protected] values : logi(0) 
.. .. [email protected] offset : num 0 
.. .. [email protected] gain  : num 1 
.. .. [email protected] inmemory : logi FALSE 
.. .. [email protected] fromdisk : logi TRUE 
.. .. [email protected] isfactor : logi FALSE 
.. .. [email protected] attributes: list() 
.. .. [email protected] haveminmax: logi TRUE 
.. .. [email protected] min  : num 0.00335 
.. .. [email protected] max  : num 3870657 
.. .. [email protected] band  : int 1 
.. .. [email protected] unit  : chr "" 
.. .. [email protected] names  : chr "layer" 
[email protected] legend :Formal class '.RasterLegend' [package "raster"] with 5 slots 
.. .. [email protected] type  : chr(0) 
.. .. [email protected] values : logi(0) 
.. .. [email protected] color  : logi(0) 
.. .. [email protected] names  : logi(0) 
.. .. [email protected] colortable: logi(0) 
[email protected] title : chr(0) 
[email protected] extent :Formal class 'Extent' [package "raster"] with 4 slots 
.. .. [email protected] xmin: num 35.8 
.. .. [email protected] xmax: num 36.7 
.. .. [email protected] ymin: num 2.4 
.. .. [email protected] ymax: num 4.65 
[email protected] rotated : logi FALSE 
[email protected] rotation:Formal class '.Rotation' [package "raster"] with 2 slots 
.. .. [email protected] geotrans: num(0) 
.. .. [email protected] transfun:function() 
[email protected] ncols : int 3240 
[email protected] nrows : int 8321 
[email protected] crs  :Formal class 'CRS' [package "sp"] with 1 slot 
.. .. [email protected] projargs: chr "+proj=longlat +ellps=WGS84 +no_defs" 
[email protected] history : list() 
[email protected] z  : list() 
+0

它不會改變我能看到的背景。你的地圖數據是什麼樣的?您可能在整個盒裝區域都有NAs。 – troh

+0

我已經下載了Landsat 8 OLI/TIRS圖像並在其中應用了迴歸模型。我將如何擺脫整個盒裝區域的NA值並僅保留湖泊?我之前用湖形文件裁剪了圖像。 –

+0

你可以顯示你的數據的'str'的​​輸出嗎? – troh

回答

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 「

+0

對不起,它沒有工作。我收到了我發佈的相同照片。 –

+0

也許指定瓷磚的寬度會改變它?沒有最少的數據示例就很難重現。 – troh

+0

我用湖的形狀文件裁剪了圖像,但仍然顯示湖區外的值 –