ca绘制文本属性

Cha*_*ase 2 graphics plot r ggplot2

在绘制与ca包的对应关系图时,有没有人知道控制行名和列名的字体大小/颜色/重量的方法?

以下代码将生成一个非常漂亮的图表,但如果有更多的属性(非常重,超重,超重的东西)或更多类的工人(peons,underlings等),那么图表会变得有点混乱而且很难分辨出什么是什么.

如果您能够以与工作人员类别不同的​​颜色列出所有属性,那将是很好的.

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)
)
Run Code Online (Sandbox Code Playgroud)

或者,有没有人知道是否有办法用ggplot2沿着这些线重现某些东西?我在网站上找不到任何可比较的内容,但我对这个包不太了解.

谢谢, - 谢谢

Geo*_*tas 6

我会尝试一些R中可用的其他对应分析函数.在其中一些函数中cex支持字符扩展因子()选项,因此您可以控制字体大小.例如

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) 
Run Code Online (Sandbox Code Playgroud)

编辑

当然,您可以从ca结果集中获取坐标,并使用ggplot2生成此图.这里我使用的是CA的res对象.

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)
Run Code Online (Sandbox Code Playgroud)