[R-sig-Geo] spplot : varying dots for multiple parameters

Roger Bivand Roger.Bivand at nhh.no
Sat Dec 12 11:39:52 CET 2009


On Fri, 11 Dec 2009, servet ahmet çizmeli wrote:

> Dear all,
>
> I am new to R and sp. Thanks for your patience. I did several hours of research
> in various places. This list is my last resort.
>
> I am trying to plot on a spatial map the punctual measurements of the
> data located in the file (https://opengeo.metu.edu.tr/test.csv). I'd like to do
> that with the tools in the lattice package as I will add more parameters on the
> same graph later. When I call spplot using the code given below, I get the
> warning:
>
> Warning messages:
> 1: In if (!x$aspect.fill) panel.height[[1]] <- x$aspect.ratio * panel.width[[1]]
> :
>  the condition has length > 1 and only the first element will be used
> 2: In if (layout.respect) { :
>  the condition has length > 1 and only the first element will be used
> 3: In heights.x[pos.heights[["panel"]]] <- heights.settings[["panel"]] *  :
>  number of items to replace is not a multiple of replacement length
>
> Question 1 : I did several trials but could not eliminate this warning. Is this
> serious?

Thank you for providing both a sample data set and your code - this makes 
trying to help very much easier! Had you also added the output of 
sessionInfo(), I might have been able to answer this question. On Linux 
x86_64 with a Cairo graphics device and current sp, I cannot reproduce 
these warnings.

>
> Question 2 : Only the dots of the parameter "SPM" varies with its magnitude. How
> to make the other parameters also have varying dot sizes?
>

The values of Si, LUT and HEX all fall into the smallest class for SPM, 
which is why no variation is seen. Is it possible that you might rather 
use:

idx = is.na(Insitu$SPM)
bSPM <- bubble(Insitu_sp[!idx,], "SPM")
plot(bSPM, split=c(1,1,2,2), more=TRUE)
bSi <- bubble(Insitu_sp, "Si")
plot(bSi, split=c(1,2,2,2), more=TRUE)
# all LUT values are zero, so nothing to plot
idx = is.na(Insitu$HEX)
bHEX <- bubble(Insitu_sp[!idx,], "HEX")
plot(bHEX, split=c(2,2,2,2), more=FALSE)

The idea is to try to do things more simply first, and only make them 
complicated when as many as possible of the oddities of the input data 
have been taken into account (like NAs, all values zero, etc.). You can 
find that the area "jumps around", as does the scaling, with different idx 
values - this needs care:

xlim <- c(28.7, 29.3)
ylim <- c(36.6, 36.8)
idx = is.na(Insitu$SPM)
bSPM <- bubble(Insitu_sp[!idx,], "SPM", xlim=xlim, ylim=ylim)
plot(bSPM, split=c(1,1,1,3), more=TRUE)
bSi <- bubble(Insitu_sp, "Si", xlim=xlim, ylim=ylim)
plot(bSi, split=c(1,2,1,3), more=TRUE)
# all LUT values are zero, so nothing to plot
idx = is.na(Insitu$HEX)
bHEX <- bubble(Insitu_sp[!idx,], "HEX", xlim=xlim, ylim=ylim)
plot(bHEX, split=c(1,3,1,3), more=FALSE)

is a possibility.


> Question 3 : I formed the code below by basing myself on an example given in the
> book of Bivand et al. I then arbitrarily changed the "scale" parameter of the
> scalebar so that it goes in a nice place. However, how could I now the real
> length of the scale bar so that I can change the "1km" string which is false
> right now.

Please leave these decorations until everything else has been settled. 
Hint: use spDistsN1() to get a km distance to use in the scale.

Hope this helps,

Roger

>
> Any ideas?
> thanks a lot from advance
> Servet
>
> rm(list=ls())
> library(sp)
>
> Insitu = read.table("test.csv", skip=3,sep=",")
> Header = read.table("test.csv", skip=1,sep=",",nrows=1)
> names(Insitu)= as.character(as.matrix(Header))
> CRS_4326 = CRS("+init=epsg:4326")
>
> Insitu_sp <-
> SpatialPointsDataFrame(cbind(Insitu[,"Boylam"],Insitu[,"Enlem"]),
> data=Insitu, proj4string=CRS_4326)
>
> idx = is.na(Insitu[,"SPM"])
> ptsize = 20/(sqrt(Insitu[!idx,"SPM"])+1)
>
> pts <- list("sp.points", Insitu_sp[!idx,"SPM"], pch = 4, col = "red",cex=ptsize)
> north <- list("SpatialPolygonsRescale", layout.north.arrow(),
>    offset = c(28.85, 36.735), scale = 0.02)
> scale <- list("SpatialPolygonsRescale", layout.scale.bar(),
>    offset = c(29, 36.735), scale = 0.1, fill = c("transparent",
>        "black"))
> txt1 <- list("sp.text", c(29, 36.745), "0")
> txt2 <- list("sp.text", c(29.1, 36.745), "1 km")
>
> my.layout <- list(txt1,txt2,scale,north)
> spplot(Insitu_sp[!idx,c("SPM","Si","LUT","HEX")],cex=ptsize,sp.layout =
> my.layout)
>
> _______________________________________________
> 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