dadrivr
2012-May-25 13:38 UTC
[R] Correlograms: using boxes and different variables on rows and columns
I'm trying to make correlograms using corrgram. See below for a simple example. #### library(corrgram) data(baseball) vars1 <- c("Assists","Atbat","Errors","Hits","Homer","logSal") vars2 <- c("Putouts","RBI","Runs","Walks","Years") corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.pie) #### I am having two problems: 1) I want to change the visual to "bars" (see Figure 1 on p. 3: http://www.datavis.ca/papers/corrgram.pdf). I tried changing the code for the upper panel to include bars, but it doesn't appear correctly: corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.bars) 2) I want to display one set of variables in the columns (vars1) and another set of variables in the rows (vars2). The reason I want to keep one set of variables in the columns and another set of variables in the rows is because I have many variables and am only interested in the correlations of vars1 with vars2 (and not of the intercorrelations of variables among vars1 or among vars2). Thus, the correlogram with separate variables in the rows and columns would be more condensed and easier to examine visually. Can I address these issues in corrgram, or is there another package that will allow me to do that? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Correlograms-using-boxes-and-different-variables-on-rows-and-columns-tp4631309.html Sent from the R help mailing list archive at Nabble.com.
Kevin Wright
2012-May-25 16:05 UTC
[R] Correlograms: using boxes and different variables on rows and columns
In general, when you have a question about a package, it is best to contact the package author directly. (In this case, me). 1. Easy. You just have to define your own panel function. I just modified panel.shade to create panel.bar panel.bar <- function(x, y, corr=NULL, ...){ usr <- par()$usr minx <- usr[1]; maxx <- usr[2] miny <- usr[3]; maxy <- usr[4] if (is.null(corr)) corr <- cor(x, y, use = "pair") ncol <- 14 pal <- col.corrgram(ncol) col.ind <- as.numeric(cut(corr, breaks = seq(from = -1, to = 1, length = ncol + 1), include.lowest = TRUE)) col.bar <- pal[col.ind] if(corr < 0) { maxy <- miny + (maxy-miny) * abs(corr) rect(minx, miny, maxx, maxy, col = pal[col.ind], border = "lightgray") } else if (corr > 0){ miny <- maxy - (maxy-miny)*corr rect(minx, miny, maxx, maxy, col = pal[col.ind], border = "lightgray") } } corrgram(auto, order=TRUE, main="Auto data (PC order)", upper.panel=panel.bar) 2. Harder. You need to create your own copy of the corrgram function and change it. Look for the call to par() and change the number of rows and columns. Then change the loops over i and j to include only the row and column numbers that you want instead of all rows and columns. Kevin On Fri, May 25, 2012 at 8:38 AM, dadrivr <dadrivr at gmail.com> wrote:> I'm trying to make correlograms using corrgram. ?See below for a simple > example. > > #### > library(corrgram) > > data(baseball) > vars1 <- c("Assists","Atbat","Errors","Hits","Homer","logSal") > vars2 <- c("Putouts","RBI","Runs","Walks","Years") > > corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.pie) > #### > > I am having two problems: > > 1) I want to change the visual to "bars" (see Figure 1 on p. 3: > http://www.datavis.ca/papers/corrgram.pdf). ?I tried changing the code for > the upper panel to include bars, but it doesn't appear correctly: > > corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.bars) > > 2) I want to display one set of variables in the columns (vars1) and another > set of variables in the rows (vars2). ?The reason I want to keep one set of > variables in the columns and another set of variables in the rows is because > I have many variables and am only interested in the correlations of vars1 > with vars2 (and not of the intercorrelations of variables among vars1 or > among vars2). ?Thus, the correlogram with separate variables in the rows and > columns would be more condensed and easier to examine visually. > > Can I address these issues in corrgram, or is there another package that > will allow me to do that? ?Thanks in advance. > > -- > View this message in context: http://r.789695.n4.nabble.com/Correlograms-using-boxes-and-different-variables-on-rows-and-columns-tp4631309.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.-- Kevin Wright