开发者

ca plotting text attributes

开发者 https://www.devze.com 2022-12-27 07:34 出处:网络
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?

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


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)


The second code block of George Dontas a really good example. Solved a big issue for me. But it took me forever to figure out that the names of the CA-objects are actually:

[YOUR_CA-CLASS-TABLE]$colcoord[,1]

and

[YOUR_CA-CLASS-TABLE]$rowcoord[,1]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号