[R] pairs(), expression in label and color in text.panel

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Nov 25 17:31:18 CET 2011



On 24.11.2011 15:59, Johannes Radinger wrote:
> Hello,
>
> I'd like to add custom labels to my pair() plot. These
> labels include math expression but they aren't correctly
> displayed...

Looks fine for me in R-2.14.0 on the windows() device (alpha, text, 
beta). (Both version and device you used are unspecified)


> Further, I want that the boxes for the text.panel (diagonal)
> have an other background color (grey80). Is that generally
> possible? If yes how do I have to set it?
>
> What I've so far is:
>
>
> panel.cor<- function(x, y, digits=2, prefix="", cex.cor)
> {
> 	usr<- par("usr"); on.exit(par(usr))
> 	par(usr = c(0, 1, 0, 1))
> 	r<- abs(cor(x, y))
> 	txt<- format(c(r, 0.123456789), digits=digits)[1]
> 	txt<- paste(prefix, txt, sep="")
> 	if(missing(cex.cor)) cex<- 0.5/strwidth(txt)
> 	
> 	test<- cor.test(x,y)
> 	# borrowed from printCoefmat
> 	Signif<- symnum(test$p.value, corr = FALSE, na = FALSE,
> 			cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
> 			symbols = c("***", "**", "*", ".", " "))
> 	
> 	text(0.5, 0.5, paste(txt,Signif), cex = 2)
> }
>
> #correlation pair plot
> pairs(df, labels=c(expression(alpha),"text",expression(beta)), lower.panel=panel.smooth, upper.panel=panel.cor)


Not easily without changing the original code, I think, but you can cheat:

pairs(iris, labels = expression(alpha, "text", beta),
     lower.panel=panel.smooth, upper.panel=panel.cor,
     diag.panel = function(...)
         rect(par("usr")[1], par("usr")[3],
              par("usr")[2], par("usr")[4], col="grey80")
)


Best,
Uwe Ligges



> Maybe someone knows how to do that and can give some hints...
>
> /Johannes
>
> --
>
> ______________________________________________
> 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