Hello, Using the Correspondence Analysis package (ca), I wonder if there is a way to further customize the plot beyond the options given in plot.ca provided by the mentioned package. The correspondence analysis I am doing consists of two datasets sharing only the rows, so the plot draw the total of columns (from both datasets) in the graph and the rows as expected. However, as in my case the number of columns in one dataset is huge, I would like to omit those points and labels in the plot. The list of parameters of plot.ca does not allow me to do this so I wonder if there is a way to force this in R. An example to see what I want is the following: library(ca) data(author) plot(ca(author), arrows=c(FALSE,TRUE)) The object "author" is composed of two datasets, I would like to omit the points corresponding to columns from a-m, while still maintaining the points in the second datasets, i.e. columns from n-z. Any help is more than appreciated. Best regards, ---sram
Milan Bouchet-Valat
2012-Jun-15 12:40 UTC
[R] Customizing a Plot in Correspondence Analysis
Le jeudi 14 juin 2012 ? 20:32 -0400, Salvador Ramirez a ?crit :> Hello, > > Using the Correspondence Analysis package (ca), I wonder if there is a way > to further customize the plot beyond the options given in plot.ca provided > by the mentioned package. > > The correspondence analysis I am doing consists of two datasets sharing > only the rows, so the plot draw the total of columns (from both datasets) > in the graph and the rows as expected. However, as in my case the number > of columns in one dataset is huge, I would like to omit those points and > labels in the plot. The list of parameters of plot.ca does not allow me to > do this so I wonder if there is a way to force this in R. > > An example to see what I want is the following: > > library(ca) > data(author) > plot(ca(author), arrows=c(FALSE,TRUE)) > > The object "author" is composed of two datasets, I would like to omit the > points corresponding to columns from a-m, while still maintaining the > points in the second datasets, i.e. columns from n-z. > > Any help is more than appreciated.This is not possible with the standard plot.ca() function. I have written small functions in my package[1] that return a ca object with only the rows or columns you specified. This is an ugly hack, but it works as long as you plot the result directly. These functions are: # Restrain CA to a subset of rows (only for plotting!) rowSubsetCa <- function(ca, indices) { ret <- ca for (i in 4:7) { ret[[i]] <- list() ret[[i]] <- ca[[i]][indices] } del <- which(!(1:nrow(ca$rowcoord) %in% indices)) ret$rowsup <- as.numeric(sapply(ca$rowsup[ca$rowsup %in% indices], function(x) x - sum(del < x))) ret$rowcoord <- matrix() ret$rowcoord <- ca$rowcoord[indices,,drop=FALSE] ret$rownames <- ca$rownames[indices] ret } # Restrain CA to a subset of columns (only for plotting!) colSubsetCa <- function(ca, indices) { ret <- ca for (i in 9:12) { ret[[i]] <- list() ret[[i]] <- ca[[i]][indices] } ret$colsup <- ret$colsup[ret$colsup %in% indices] ret$colsup <- as.numeric(lapply(ca$colsup, function(x) x - sum(indices < x))) ret$colcoord <- matrix() ret$colcoord <- ca$colcoord[indices,,drop=FALSE] ret$colnames <- ca$colnames[indices] ret } In you case, you can do something like plot(colSubsetCa(ca(author), 1:13)) Hope this helps 1: https://r-forge.r-project.org/scm/viewvc.php/pkg/rcmdr-tms/R/showCorpusCa.R?view=markup&root=rcmdr-tms
Apparently Analagous Threads
- Scores in Dimensions in Correspondence Analysis
- How to use PC1 of PCA and dim1 of MCA as a predictor in logistic regression model for data reduction
- correspondence analysis and canonical correspondence analysis in R
- Correspondence and detrended correspondence analysis
- correspondence analysis