views:

89

answers:

1

Does anyone know of a way to control the font size/color/weight of the row and column names when plotting a correspondence plot with the ca package?

The following code will produce a very nice looking chart, though if there were more attributes (very heavy, super heavy, something more than super heavy) or more classes of workers (peons, underlings, etc) then the graph will get a little cluttered and hard to tell what was what.

It would be nice if you could list all the attributes in a separate color than the categories of workers.

library(ca)
data("smoke")

plot(ca(smoke)
  , map = "symmetric"
  , what =c("active","active")
  , mass = c(T,T)
  , contrib = "absolute"
  , col = c("red","blue")
  , pch = c(15,17,15,17)
  , labels = c(2,2)
  , arrows = c(T,F)
)

Alternatively, does anyone know if there is a way to reproduce something along these lines with ggplot2? I didn't find anything on the website that seemed comparable, but I don't know much about the package.

Thanks, -Chase

+3  A: 

I would try some of the other correspondence analysis functions available in R. In some of them the character expansion factor (cex) option is supported, so you can control the font size. e.g.

library(FactoMineR)
res<-CA(smoke, ncp=5, row.sup=NULL, col.sup=NULL, graph = FALSE)
plot.CA(res, axes=c(1, 2), col.row="red", col.col="blue", label=c("col","col.sup", "row", "row.sup"),cex=.7)

library(MASS)
biplot(corresp(smoke, nf = 2),cex=.7,col=c("red","blue"))

library(anacor) # actually I didn't find a way to control font size here
res <- anacor(smoke, scaling = c("Benzecri", "Benzecri"),ndim=2) 
plot(res, plot.type = "jointplot", conf = NULL) 

EDIT

Of course you could get the coordinates from the ca resultset and generate this plot using ggplot2. Here I'm using the res object from CA.

df <- data.frame(dim1 = c(res$col$coord[,1],res$row$coord[,1]), 
dim2 = c(res$col$coord[,2],res$row$coord[,2]),
type=c(rep(1,length(res$col$coord[,1])),rep(2,length(res$row$coord[,1]))))

library(ggplot2)
qplot(dim1,dim2,data=df,colour=factor(type)) +
geom_text(aes(label=rownames(df)),size=3)
gd047
This is exactly what I needed to help me on my way. I apologize for not responding sooner, I've been traveling. Thanks again!
Chase