使用日志缩放颜色防止灰度背景到光栅gplot

时间:2013-05-28 16:36:31

标签: r ggplot2

使用gplot()绘制栅格会产生一个漂亮的地图,例如: enter image description here

由于可变比例(总体)涵盖许多数量级,因此优选对数比例。但是当这个应用于颜色变量时(通过向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')

提前致谢。

1 个答案:

答案 0 :(得分:3)

只需将na.value的{​​{1}}参数设置为适当的值,例如scale_fill_gradient'white'NA引起,即log,在log(0) = -Inf中被解释为NA

相关问题