[R-sig-Geo] upper bounds for values in color scale in spplot

Roger Bivand Roger.Bivand at nhh.no
Fri Oct 12 10:53:39 CEST 2007


On Fri, 12 Oct 2007, Brad Christoffersen wrote:

> Dear R mappers,
>
> I'm just getting started with sp and maptools in R, and I have limited 
> familiarity with lattice() and how spplot interfaces with lattice() in 
> terms of commands.  I would like to know how to keep the range of values 
> represented by a color scale on a series of maps constant.

Reading the levelplot help page after library(lattice) usually helps. The 
arguments you need are at= and col.regions=, which let you fix the class 
intervals and the colour palette. You will need to try out values that 
suit, but this should get you there.

Roger

>
> This is the code I'm running that generates 8 maps across 4 rows and 2 columns.
> You will see that it produces maps that have different upper bounds on the
> respective color scales.  I'm interested in having a constant color scale for
> each group of 4 maps (1 scale for each column of maps that are plotted) based
> on the largest value in the data (or by just prescribing the upper and lower
> bounds with constants).
>
> Any help is much appreciated!
> Thanks,
> Brad C.
>
> library(lattice)
> library(sp)
> library(maptools)
> test <- read.table(##see data below##)
> attach(test)
> trellis.par.set(sp.theme()) # sets bpy.colors() ramp
> seasons <- c("winter", "spring", "summer", "fall")
> for(i in 1:length(seasons)){
> 	coords <- cbind(as.numeric(as.character(test[quarter %in% seasons[i],"lon"])),
> as.numeric(as.character(test[quarter %in% seasons[i],"lat"])))
> 	data <- as.data.frame(test[quarter %in% seasons[i],c("alpha.hat","beta.hat")])
> 	test.sp <- SpatialPixelsDataFrame(coords, data)
> 	alpha <- spplot(test.sp, "alpha.hat", scales = list(draw = TRUE))
> #		xlab="Degrees longitude", ylab="Degrees latitude", cex=.01)
> 	beta <- spplot(test.sp, "beta.hat", scales = list(draw = TRUE))
> #		xlab="Degrees longitude", ylab="Degrees latitude")
> 	print(alpha, split = c(1,i,2,4), more=TRUE)
> 	if(i != 4) print(beta, split = c(2,i,2,4), more=TRUE) else print(beta, split =
> c(2,i,2,4), more=FALSE)
> 	}
>
> #### data to import into "test" above ####
> # Exported using write.csv()
>
> "","lon","lat","quarter","alpha.hat","beta.hat"
> "1","-92","15","fall",6.65227439310417,56.98796936965
> "2","-91","16","fall",5.7887515614357,61.4959602856346
> "3","-92","16","fall",8.3574938986946,39.3233936656175
> "4","-93","16","fall",6.59178338045291,51.1710742349428
> "5","-94","16","fall",4.59110354447175,72.4631790313551
> "6","-96","16","fall",3.39120062305053,61.3498455235854
> "7","-97","16","fall",3.72637499733858,52.3827509555908
> "8","-100","17","fall",3.32679271676835,57.9245201009673
> "9","-92","17","fall",7.8180071249829,42.72784154996
> "10","-93","17","fall",6.83894383129027,54.4726918059386
> "3190","-92","15","winter",5.46418721415736,54.6602669154477
> "3191","-91","16","winter",10.2567049399226,26.8445099823192
> "3192","-92","16","winter",8.47780749631668,32.3555645381505
> "3193","-93","16","winter",8.02490919053258,38.1741888219237
> "3194","-94","16","winter",9.26825779141845,31.6804438316389
> "3195","-96","16","winter",7.42583760477561,32.4318502183180
> "3196","-97","16","winter",7.15366354446019,30.4092071610074
> "3197","-100","17","winter",5.67248315575543,44.0629887199626
> "3198","-92","17","winter",11.0324295494684,28.5398502105252
> "3199","-93","17","winter",12.8600152825316,25.8707202327790
> "1064","-92","15","spring",3.61863154993334,165.857349319137
> "1065","-91","16","spring",10.1643339841701,35.2421643628567
> "1066","-92","16","spring",7.57240369751446,46.9922847457852
> "1067","-93","16","spring",6.22249309807625,56.292359117006
> "1068","-94","16","spring",4.68274375255797,74.3825475754281
> "1069","-96","16","spring",5.53655775167911,44.1263777723619
> "1070","-97","16","spring",7.97757426122346,27.6282118121658
> "1071","-100","17","spring",6.56565778175741,31.7130717161184
> "1072","-92","17","spring",7.6609568130759,55.1152061731614
> "1073","-93","17","spring",8.0322728962686,50.598411876406
> "2127","-92","15","summer",9.72176297639579,71.2388658845007
> "2128","-91","16","summer",16.4747820437274,24.4358645774566
> "2129","-92","16","summer",14.0292926267460,27.8787650995959
> "2130","-93","16","summer",13.1831296281448,27.3284323593481
> "2131","-94","16","summer",6.1805787873833,58.44229189654
> "2132","-96","16","summer",5.77117377664185,41.3812553952903
> "2133","-97","16","summer",5.98738435242406,35.7155813363363
> "2134","-100","17","summer",5.72083279663587,37.0908537701739
> "2135","-92","17","summer",9.2083842635031,55.218659463404
> "2136","-93","17","summer",13.5244943586978,37.5585163321001
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list