2013-05-28 46 views
1

繪製使用gplot()光柵產生一個很好的地圖,e.g: enter image description here防止灰色背景成光柵gplot與日誌縮放的顏色

由於可變規模(人口)覆蓋許多數量級,對數標度是優選的。但是,當這個被應用於彩色可變(通過添加trans='log'參數scale_fill_gradient),人口零的領域最終灰色:

enter image description here

有誰知道如何防止這種情況?這是我正在使用的代碼:

require(raster, rgdal, ggplot2) 
pop = readGDAL("usa_population.tif") 
p = raster(pop, layer=1, values=TRUE) 
s <- stack(p) 
gplot(s) + geom_tile(aes(fill = value)) + 
    scale_fill_gradient(low = 'white', high = 'blue', trans='log') 

在此先感謝。

+2

我的猜測:na.value =「grey50」被用於log(0)? – baptiste

回答

3

只要將scale_fill_gradient的參數na.value設置爲適當的值,例如, 'white'NA是由log引起的,即log(0) = -Inf,其在ggplot2中被解釋爲NA

+0

-Inf但我想它在ggplot中變成了NA? – baptiste

+0

是的,'-Inf'被解釋爲與'NA'相同。 –

+0

謝謝。應該發現那個! – geotheory