【问题标题】:Formatting Issue with barchart() of Cluster Analysis聚类分析的 barchart() 格式问题
【发布时间】:2013-10-03 09:13:53
【问题描述】:

我已经为我的聚类分析创建了一个段剖面图,但我遇到了barchart() 命令的格式问题。这是我创建的图表。明显的问题是我的台词靠得太近而无法阅读。

在这里你可以看到我用来创建这个图表的代码。有人可以告诉我要添加什么以使此图表可读吗?下面是我使用的代码示例。

用于重现我们使用的聚类和 PCA 的 R 代码:

## if not installed, install: install.packages("flexclust")
library("flexclust")
load("vacpref.RData")
cl6 <- kcca(vacpref, k=vacpref6, control=list(iter=0),
            simple=FALSE, save.data=TRUE)
summary(cl6)

变量的层次聚类

varhier <- hclust(dist(t(vacpref)), "ward")
par(mar=c(0,0,0,15))
plot(as.dendrogram(varhier), xlab="", horiz=TRUE,yaxt="n")

主成分投影

vacpca <- prcomp(vacpref)

用于生成段分离图的 R 代码

pairs(cl6, project=vacpca, which=1:3, asp=TRUE,points=FALSE, 
      hull.args=list(density=10))

生成段定位图的R代码:

col <- flxColors(1:6)
col[c(1,3)] <- flxColors(1:4, "light")[c(1,3)]
par(mar=rep(0,4))
plot(cl6, project=vacpca, which=2:3,
     col=col,asp=TRUE,points=F,hull.args=list(density=10),axes=FALSE)
projAxes(vacpca, minradius=.5, which=2:3, lwd=2, col=”darkblue”)

用于生成段剖面图的 R 代码:

barchart(cl6, shade=TRUE, which=rev(varhier$order),legend=TRUE)

最后一个命令是我用来创建分段剖面图的命令,但我不确定之前的命令是否会以任何方式影响它。我是 R 新手。

【问题讨论】:

  • 点图或平行坐标图肯定有助于提高清晰度和可读性。

标签: r data-visualization cluster-analysis


【解决方案1】:

我经常使用的一个技巧是通过导出图像来更改宽度/高度和分辨率。试试这个:

png("c:\\temp\\myCrazyPlot.png", res=250, height=8, width=12, unit="in")
  barchart(cl6, shade=TRUE, which=rev(varhier$order),legend=TRUE)
  # And whatever other plot commands for the same plot
dev.off()

然后去检查你的 .png 文件。通过修改高度和宽度,您可以以某种方式调整标签在 y 轴上的间距。你甚至可以让它的高度比它的宽度长,让标签散开。 (我认为目前你不能这样做,因为这是你屏幕的最大高度?)

【讨论】:

  • 谢谢,但它不起作用。它像你说的那样扭曲图像,但保持重叠的标签。它确实使阅读更容易,但对于报告来说还不够好。我可以在 R 中做任何其他建议吗?
  • @Brennen 抱歉,没用。请尝试this thread的建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-14
相关资源
最近更新 更多