[R] lattice plotting character woes

Murray Jorgensen maj at stats.waikato.ac.nz
Tue Aug 26 03:24:33 CEST 2008


The following reproducable code shows the setting of my problem:

set.seed(260808)
n = 50
x = rnorm(n)
y = rnorm(n)
z = ceiling(runif(n,0,4))
g = runif(n,0,6)
G = factor(ceiling(g))
xyplot(y ~ x | G)
plsy <- trellis.par.get("plot.symbol")
plsy$pch = z
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x | G)

plsy$pch = as.character(z)
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x | G)

Unfortunately it does not reproduce the problem, which is that instead 
of the plotting characters being determined by the value of G, they are 
all the same, corresponding to the lowest level of G.

Here is my actual output:

 > patches = read.csv(apf,header=TRUE)
 > summary(patches)
     X                      URBAN_AREA   NO_PATCHES       MEAN_AREA
Mode:logical  CENTRAL AUCKLAND ZONE: 4  Min.   :   0.0   Min.   :   0.00
NA's:83       CHRISTCHURCH         : 4  1st Qu.:  81.5   1st Qu.:  11.64
               DUNEDIN              : 4  Median : 200.0   Median :  23.19
               HAMILTON ZONE        : 4  Mean   : 375.5   Mean   : 323.08
               HASTINGS ZONE        : 4  3rd Qu.: 524.5   3rd Qu.: 149.54
               INVERCARGILL         : 4  Max.   :3083.0   Max.   :6609.34
               (Other)              :59                   NA's   :   3.00
     MAX_AREA            MIN_AREA         STD_AREA           MEAN_EDGE
  Min.   :1.008e+01   Min.   :0.0029   Min.   :    3.115   Min.   : 1075
  1st Qu.:1.716e+02   1st Qu.:0.1605   1st Qu.:   24.939   1st Qu.: 1867
  Median :2.336e+03   Median :0.2516   Median :  185.198   Median : 2669
  Mean   :6.211e+04   Mean   :0.5888   Mean   : 3888.733   Mean   : 6584
  3rd Qu.:3.670e+04   3rd Qu.:0.4713   3rd Qu.: 2148.932   3rd Qu.: 6149
  Max.   :1.449e+06   Max.   :8.8260   Max.   :64028.083   Max.   :94641
  NA's   :4.000e+00   NA's   :4.0000   NA's   :    4.000   NA's   :    4
     MAX_EDGE           MIN_EDGE          STD_EDGE           MEAN_E_A
  Min.   :    2340   Min.   :  34.35   Min.   :   290.2   Min.   :0.01491
  1st Qu.:   20369   1st Qu.: 162.04   1st Qu.:  2919.3   1st Qu.:0.03320
  Median :  124243   Median : 193.47   Median :  9182.8   Median :0.03910
  Mean   :  841731   Mean   : 286.33   Mean   : 53940.9   Mean   :0.03924
  3rd Qu.:  913745   3rd Qu.: 325.62   3rd Qu.: 56914.0   3rd Qu.:0.04527
  Max.   :13086956   Max.   :1770.00   Max.   :584281.0   Max.   :0.06010
  NA's   :       4   NA's   :   4.00   NA's   :     4.0   NA's   :4.00000
     MAX_E_A           MIN_E_A            STD_E_A           AREA.ZONE
  Min.   :0.01755   Min.   :0.000900   Min.   :0.002378   Min.   :  1114
  1st Qu.:0.08890   1st Qu.:0.001526   1st Qu.:0.016550   1st Qu.: 13996
  Median :0.10146   Median :0.002900   Median :0.018500   Median : 38015
  Mean   :0.14431   Mean   :0.005689   Mean   :0.019567   Mean   : 60883
  3rd Qu.:0.12040   3rd Qu.:0.008592   3rd Qu.:0.020784   3rd Qu.: 84787
  Max.   :1.20530   Max.   :0.024350   Max.   :0.059000   Max.   :264735
  NA's   :4.00000   NA's   :4.000000   NA's   :4.000000   NA's   :     3
  No..patches.100.ha   X.1           Buffer.zone
  Min.   :0.0000     Mode:logical   Min.   : 0.000
  1st Qu.:0.3534     NA's:83        1st Qu.: 5.000
  Median :0.5653                    Median :10.000
  Mean   :0.6952                    Mean   : 9.157
  3rd Qu.:0.9080                    3rd Qu.:20.000
  Max.   :2.9374                    Max.   :20.000

 > # clean
 > patches = patches[,-c(1,18)]
 > patches = patches[-c(20,81,82,83),]
 > cnames = patches[,1]
 > acn = abbreviate(cnames)
 > zone = patches[,17]/5
 > names(acn) = NULL
 > Region = factor(acn)
 > lpatches = patches
 > for (i in 2:16) lpatches[,i] = log10(patches[,i])
 > # zone not transformed
 > lpatches.pca = princomp(lpatches[,-c(1,17)],cor=FALSE)
 > x = lpatches.pca$scores[,1]
 > y = lpatches.pca$scores[,2]
 > zz = as.character(patches$Buffer.zone/5)
 > plsy <- trellis.par.get("plot.symbol")
 > plsy$pch = zz
 > trellis.par.set("plot.symbol",plsy)
 > xyplot(y ~ x |Region)
 > table(zz)
zz
  0  1  2  4
19 20 20 20

I would dearly like to have my plotting symbols indicate the zone but I 
am frustrated.

Curiously I may put other (numeric or character) variable in place of zz 
and get variable plotting characters.

Murray
-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk    Home +64 7 825 0441    Mobile 021 1395 862



More information about the R-help mailing list