I have to plot a raster with a custom colorkey and every text in bold for clear visibility. assuming the following raster:
ras <- raster(matrix(runif(100 * 100, min = 10, max = 250),
nrow = 100, ncol = 100), xmn = 0, xmx = 10, ymn = 0, ymx = 10)
I have the following colorkey and custom breaks and labels:
color_range <- colorRampPalette(c("white", "deepskyblue3","darkblue"))
my_colors <- color_range(12)
my.at=c(seq(20,240,by=20),Inf)
my.brks=c(seq(20,240,by=20),Inf)
myColorkey <- list(at=my.at, labels=list(c("20","40","60","80","100","120","140","160","180","200","220","240","Inf"),
fontface = "bold"),cex=2,font=2)
and the following level plot code:
library(lattice)
levelplot(ras, col.regions=my_colors, at=my.at, colorkey=myColorkey,margin=F,
cex.main =0.3,line = 0.5, scales = list(x = list(cex = 1), y = list(cex = 1)),
xlab = list("longitude (°E) ",fontface = "bold"), ylab =list("latitude (°N)",fontface = "bold"))
but the labels don't show up as I mentioned:
[![wrong labels][1]][1]
if I remove the cex condition in colorkey, I get the proper labels but not in bold:
myColorkey <- list(at=my.at, labels=c("20","40","60","80","100","120","140","160","180","200","220","240","Inf"))
How to achieve the correct lables and bold format? [1]: https://i.stack.imgur.com/MVvw8.png