[Rd] proposal: lattice/panel.levelplot with show.z.values
Wolfram Fischer - Z/I/M
wolfram@fischer-zim.ch
Thu Jan 23 17:57:02 2003
I suggest to add an argument to levelplot
which displays the z values in the cells.
In the special case of a correlogram the correlation values could
be rotated by 45 degres when the correlation is positive and by
-45 degress when the correlation is negative (see example).
Wolfram
NB: The same code should be to panel.catlevelplot if this panel
function will be implemented.
#---- ADDITIONAL ARGUMENTS FOR panel.levelplot() -------------------
show.z.values = FALSE, # display z values in the cells
# if -1: if( srt == 0 ) srt <- 45
# if( z < 0 ) srt <- -srt
cex = 1, # size of z values
signif = 2, # number of significant digits of z values
srt = 0, # rotation of z values
#---- ADDITIONAL CODE AT THE END OF panel.levelplot() --------------
if( show.z.values ){
if( show.z.values < 0 )
srt <- ifelse( srt==0, 45, srt ) * sign( z[subscripts] )
ltext(
x = x[subscripts]
, y = y[subscripts]
, labels = signif( z[subscripts], signif )
, cex = cex
, srt = srt
)
}
#---- EXAMPLE ------------------------------------------------------
library(EMV)
data(swiss)
example.corplot.swiss <- function( show.z.values=-1, ... ){
x.cor <- cor( knn( as.matrix( swiss ) )$data )
diag( x.cor ) <- 0
x.names <- colnames( swiss )
x.cor.data <- data.frame(
x = rep( x.names, length( x.names ) )
, y = rep( x.names, each=length( x.names ) )
, val = as.vector( x.cor )
)
print( levelplot( val ~ x + y, data = x.cor.data
, show.z.values = show.z.values
, scales= list(
x = list( labels = x.names, rot=90, alternating=F
, at = 1 : length( x.names ) )
, y = list( labels = x.names, alternating=F
, at = 1 : length( x.names ) )
)
, zlim = c( -1, 1 )
, ...
))
}