[R-sig-Geo] Customizing levelplot coloring scheme in r

John Baumgartner johnb@um@ @end|ng |rom gm@||@com
Tue Oct 18 22:06:14 CEST 2022


To have the color ramp diverge around 0 (with uneven positive/negative
color ramp extents) you can use
https://gist.github.com/johnbaums/306e4b7e69c87b1826db

devtools::source_gist('306e4b7e69c87b1826db')
diverge0(FPlot10, 'RdBu') + latticeExtra::layer(sp.lines(world.outlines.sp))


On Fri, 14 Oct 2022 at 12:28, ani jaya <gaaauul using gmail.com> wrote:
>
> my suggestion is:
>
> colfunc<-colorRampPalette(c("blue","white","red"))
>
> FPlot10 <- levelplot(FDifference5,margin=F,at=c(seq(-50,150,10)),pretty=TRUE,
> col.regions=colfunc(200),...)
>
> Adding a col.regions argument maybe solve the problem.
>
> On Thu, Oct 13, 2022 at 6:11 AM Edzer Pebesma
> <edzer.pebesma using uni-muenster.de> wrote:
> >
> > Look up the col.regions argument.
> >
> > On 12/10/2022 16:44, rain1290--- via R-sig-Geo wrote:
> > > I have climate data that I have plotted on a global map using a levelplot map. However, I am trying to adjust the default coloring scheme to allow for only blue and red shades to appear. Ideally, I am trying to showcase blue for the positive values, and red for the negative values, along with a whitish coloring near and at 0. The default coloring scheme isn't bad, but I think a blue-red-white coloring would allow the plot to appear more visually pleasing. Here is the code that I have now to create my current levelplot:
> > >
> > > #packages installed
> > >
> > >
> > > library(raster)
> > > library(ncdf4)
> > > library(maps)
> > > library(maptools)
> > > library(rasterVis)
> > > library(ggplot2)
> > > library(rgdal)
> > > library(sp)
> > > library(gridExtra)
> > > library(grid)
> > > library(RColorBrewer)
> > >
> > > #Using levelplot
> > >
> > > FPlot10 <- levelplot(FDifference5,margin=F,at=c(seq(-50,150,10)),pretty=TRUE,
> > > par.settings=mapTheme, main="Higher end")
> > > FM10 <- FPlot10 + latticeExtra::layer(sp.lines(world.outlines.sp))
> > >
> > > This yields a range of nice default colors, but I'd like to adopt something with only shades of red and blue (with white at and around 0). I can do it easily in ggplot, but levelplot appears completely different in using color commands (if they exist). Is that even possible in levelplot?
> > > Thank you!
> > >       [[alternative HTML version deleted]]
> > >
> > > _______________________________________________
> > > R-sig-Geo mailing list
> > > R-sig-Geo using r-project.org
> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> > --
> > Edzer Pebesma
> > Institute for Geoinformatics
> > Heisenbergstrasse 2, 48151 Muenster, Germany
> > Phone: +49 251 8333081
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list