[R] Plotrix Trick

David Winsemius dwinsemius at comcast.net
Thu Jun 24 18:13:53 CEST 2010


On Jun 24, 2010, at 11:38 AM, Lorenzo Isella wrote:

> Dear Hrishi,
> I am almost there, thanks. The only small problem left is to convince
> also the colorbar to plot the values I want.
> Consider the small snippet at the end of the email: colors and numbers
> inside the cells are OK, but the legend shows the extremes of the log
> transformed data instead of the original one.
> Any suggestions?

Why don't you emulate the seconde example of the help page for  
color2D.matplot and leave out the show legend and then add one after  
the plotting has been done?

-- 
David.
> Cheers
>
> Lorenzo
>
>
> #########################################################
>
> library(plotrix)
>
>
> set.seed(1234)
>
> myseq <- abs(rnorm(25))
>
> myseq[20] <- 100 #introduce outlier!
>
> A <- matrix(myseq, ncol=5,nrow=5)
>
>
> pdf("test_color_scale_log-fixed.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=0,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)
> for(i in 1:5) {
>        for(j in 1:5) {
>
> text(i-0.5,j-0.5,formatC(A[6-j,i],format="f",digits=1),col="white")
>        }
> }
> box()
> par(oldpar)
> dev.off()
>
>
>
>
>
>
>> Lorenzo,
>>
>> This is a bit ugly but should work. Instead of using plotrix's
>> show.values,
>> use the text() command:
>>
>>
>> for(i in 1:5) {
>>        for(j in 1:5) {
>>                text(i-0.5,j-0.5,format(A[6- 
>> j,i],digits=3),col="white")
>>        }
>> }
>>
>> -- 
>> View this message in context:
>> http://r.789695.n4.nabble.com/Plotrix-Trick-tp2265893p2266390.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list