, ggplot2.
:
:
, . , (, → ), ( → ). .
. , ( → → → ), . , . .
- , .
; fg.quant , "" . bw.scale /: bw.scale=c(0, 0.5) , (0,5), .
, . , , .
r.1 <- raster(x=matrix(rowSums(expand.grid(1:10, 1:10)), nrow=10),
xmn=0, xmx=10, ymn=0, ymx=10)
r.2 <- raster(x=matrix(rnorm(16), nrow=4),
xmn=3, xmx=7, ymn=3, ymx=7)
BGPlot <- function(fg,
bg,
cols=c('red', 'green'),
fg.quant=c(0, 1),
bw.scale=c(0, 1),
plot.title='',
leg.name='Value') {
library(ggplot2)
fg.q <- quantile(fg, fg.quant)
fg.min <- fg.q[1]
fg.max <- fg.q[2]
# rescale fg
fg.sc <- (fg-fg.q[1]) / (fg.q[2]-fg.q[1])
fg.sc[fg.sc<0] <- 0
fg.sc[fg.sc>1] <- 1
fg.sc <- fg.sc + 0.1
ifelse((fg.max-fg.min)/10>=1, n.dgts <- 0, n.dgts <- 1)
fg.breaks <- round(seq(fg.min, fg.max, l=5), n.dgts)
fg.breaks[1] <- ceiling(fg.min*(10^n.dgts))/(10^n.dgts)
fg.breaks[5] <- floor(fg.max*(10^n.dgts))/(10^n.dgts)
fg.labs <- paste0(c(paste0(round(fg.min, n.dgts+1), '-'),'','','',''),
fg.breaks,
c('','','','',paste0('-', round(fg.max, n.dgts+1)))
)
bg.sc <- (bg-minValue(bg)) /
(maxValue(bg)-minValue(bg)) *
(bw.scale[2]-bw.scale[1]) + bw.scale[1] -1.1
r <- merge(fg.sc, bg.sc)
r.df <- as.data.frame(rasterToPoints(r))
names(r.df) <- c('Longitude', 'Latitude', 'Value')
mid.Lon <- mean(r.df$Longitude)
mid.Lat <- mean(r.df$Latitude)
vals <-c(-1.1,-0.1, seq(0.1,1.1,l=length(cols)))
dp <-seq(fg.min,fg.max,l=length(cols))
p <-
ggplot() +
geom_point(data=data.frame(x = rep(mid.Lon, length(cols)),
y = rep(mid.Lat, length(cols)),
c = dp),
aes(x, y, color=c)) +
scale_color_gradientn(colours = cols,
breaks=fg.breaks,
labels=fg.labs,
name=leg.name) +
geom_raster(data=r.df, aes(x=Longitude, y=Latitude, fill=Value)) +
scale_fill_gradientn(colours = c('black', 'white', cols),
values = vals,
rescaler = function(x,...) x,
oob = identity,
guide = "none") +
ggtitle(label=plot.title) +
theme_light() +
labs(list(x='Lon', y='Lat')) +
theme(axis.text.y=element_text(angle=90, hjust=0.5)) +
coord_equal()
return(p)
}
BGPlot(fg=r.2, bg=r.1, cols=c('red', 'green'), fg.quant=c(0.01, 0.99), bw.scale=c(0, 0.8), plot.title='Chlorophyll Concentration', leg.name='CHL')

" ":

EDIT: , R- 'RStoolbox'
RStoolbox. ggR , ggRGB RGB.
library(ggplot2)
library(RStoolbox)
ggR(BACKGROUND_IMAGE, geom_raster=FALSE) +
geom_raster(...) # here comes standard raster plot