# [R-sig-Geo] Does plotKML handle skewed diverging continuous raster?

DAlcaraz txomingo99 at gmail.com
Sun Sep 14 11:36:29 CEST 2014

```Hi,
First of all, thank you very much for your great job with the plotKML
package for R. It is simply GREAT!!!
However, I've been fighting during one week with this issue and I wonder
whether the package still does not handle it.
How can a plot a kml from a raster whose values show deviations from 0, but
Ideally, I would like negative values in reds, positive values in blues, and
zero values in grey.

Domingo

PS: I've pasted below a trivial example showing how the "plot" function can
handle this issue but the plotKML does not.

install.packages("raster", dep=T)
install.packages("RColorBrewer", dep=T)
install.packages("plotKML", dep=T)
library(raster)
library(RColorBrewer)
library(plotKML)

r<- raster(ncol=5,nrow=2)
values(r) <- c(-5,-4,-1,0,0,3,-2,-6,-6,-6) #Positive and Negative changes
as.matrix(r)
hist(r, main="Diverging skewed distribution of raster data")

DivColorBreaks <- c(-6,-3,-0.1,0.1,3,6)#
NDivBreaks <- length(DivColorBreaks)-1
DivColPalette <- colorRampPalette((brewer.pal(NDivBreaks, "RdBu")),
space="Lab")
DivCols <- DivColPalette(NDivBreaks)

plot(r, useRaster=FALSE,
col=  DivCols, breaks=DivColorBreaks)
#In the plot graph:
#pixel r1,c3 = -1 is in reds. CORRECT
#pixels r1,c4&5 = 0 are in grey. CORRECT

kml_open("DivSkewd.kml")
kml_layer.Raster(r, plot.legend = TRUE, metadata = NULL,
png.width = ncol(r), png.height = nrow(r),
min.png.width = 800,
colour_scale =  DivCols, #the problem must be here?
#Here I would need sth like "breaks=DivColorBreaks"
raster_name="DivSkewd.png")
kml_close("DivSkewd.kml")
#In DivSkewd.png:
#pixel r1,c3 = -1 is in grey. INCORRECT
#pixels r1,c4&5 = 0 are in blue. INCORRECT

#How could I plot the raster so that it fairly displays
#which pixels have negative values in red and positive values in blue?

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Does-plotKML-handle-skewed-diverging-continuous-raster-tp7587124.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

```