Skip to content
Prev 9756 / 29559 Next

fix color scale

Hi Peter,

I am not sure which plot function you are using, but I did something
similar where I plotted a series of maps for crop yields with a
constant scale for yield, using sp.plot. My data were in an attribute
table linked to a polygon, whereas yours are grids, but maybe
something in the following can be used?

  # Loop through columns of shapefile (eval.shp2) to plot: Yield from
various cultivars
  for (i in 4:13) {

   print(paste("Plotting column: ", i))  # Column counter

    # Establish scale limits and title vector
      scmax  <- round(max(eval.shp2 at data[, 4:12]) / 100, 0) * 100  #
Set max scale value
      scmin  <- round(min(eval.shp2 at data[, 4:12]) / 100, 0) * 100  #
Set min scale value
      byval  <- 25
      titlevec <- paste("district maize yields (kg/ha) 1981-99:
Cultivar", culnames[i - 3])

    # Spplot
    print(spplot(eval.shp2[-c(22,69),], z = i,
          sp.layout = list(sa.lst),
          col.regions = topo.colors(500),
          at = seq(scmin, scmax, by = byval), main = titlevec))
  }

In your case, since you are using grids, maybe you can read the
interpolated grids' metadata first to extract the max and min and
values for setting your scale.  Or perhaps you know in advance what
the max and min should be, and can simply enter those values?

Hope this is somewhat useful.

Cheers, Lyndon
On Thu, Oct 28, 2010 at 3:12 PM, Peter Larson <pslarson2 at gmail.com> wrote: