Plot issues - legend bar scale, breaks, legend, decimals

旧街凉风 提交于 2019-12-05 10:31:44

You can avoid log scale (as some users said you) using classIntervals() function from classInt package.

Using levelplot() (in my opinion the result is better than raster::plot() function):

# Normal breaks
break1 <- classIntervals(predictors[[12]][!is.na(predictors[[12]])], n = 50, style = "equal")

levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])

# Using quantiles
break1 <- classIntervals(predictors[[12]][!is.na(predictors[[12]])], n = 50, style = "quantile")

levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])

Also, you have more options to choose, such like sd, pretty, kmeans, hclust and others.


Adding polygons and point to the plot

First, I'll save the plot above to p, the line is too long for this example:

p <- levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])

I'll use the same data than your, wrld_simpl data, as polygons to add into the plot and I'll create points to be added to the plot also.

library(maptools)
library(rgeos)

data(wrld_simpl)
pts <- gCentroid(wrld_simpl, byid = T)

To add lines, polygons, points or even text, you can use layer() function and a panel.spplot object:

p + layer(sp.polygons(wrld_simpl)) + layer(sp.points(pts))

Finally, you can also change color, fill, symbology, and so on:

p + layer(sp.polygons(wrld_simpl,col='firebrick')) + layer(sp.points(pts,pch = 12,col='red'))

Check ?panel.spplot for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!