[R] Plotrix Trick
Lorenzo Isella
lorenzo.isella at gmail.com
Wed Jun 23 19:01:13 CEST 2010
Dear All,
I am using the plotrix library to plot some matrices.
I have a problem: some of my data are outliers, hence using a linear
color scale does not work very well (you would see too many cells having
a similar, indistinguishable color). See the code snipped at the end of
the email.
Plotting the logarithm of the data gets the job done, but my problem is
that I would like to write in every cell the value of the corresponding
entry of the original matrix, not is logarithm.
Does anyone know how to get this done? Or the other way around: leave
the data as is, but use a color log scale.
Many thanks
Lorenzo
library(plotrix)
set.seed(1234)
myseq <- abs(rnorm(25))
myseq[20] <- 100 #introduce outlier!
A <- matrix(myseq, ncol=5,nrow=5)
#nasty looking figure
pdf("test_color_scale.pdf")
oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1,
cex.axis=1.4,cex.lab=1.6,cex.main=1.6)
color2D.matplot(A,main="Title",c(0.2,1),c(0.2,0.5),c(0,0),
xlab = "",
ylab="",
show.legend=TRUE,
show.values=1,vcol="black",vcex=1, axes=FALSE)
## axis(1,at=c(0.5,1.5,2.5,3.5,4.5),labels=prefix_vec_short)
## axis(2,at=rev(c(0.5,1.5,2.5,3.5,4.5)),labels=prefix_vec_short)
box()
par(oldpar)
dev.off()
#this looks better, but in each cell I would like to see the same
#numbers as before.
pdf("test_color_scale_log.pdf")
oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1,
cex.axis=1.4,cex.lab=1.6,cex.main=1.6)
color2D.matplot(log(A),main="Title",c(0.2,1),c(0.2,0.5),c(0,0),
xlab = "",
ylab="",
show.legend=TRUE,
show.values=1,vcol="black",vcex=1, axes=FALSE)
## axis(1,at=c(0.5,1.5,2.5,3.5,4.5),labels=prefix_vec_short)
## axis(2,at=rev(c(0.5,1.5,2.5,3.5,4.5)),labels=prefix_vec_short)
box()
par(oldpar)
dev.off()
More information about the R-help
mailing list