0

Rで提供されているコードを使用しました: クラスター化されたマトリックス ヒートマップ (同様のカラー パターンがグループ化されている) を正常に表示するにはどうすればよいですか?ただし、Y 軸をテキスト ラベルに置き換えることはできません。

library(reshape2)
library(ggplot2)

# Create dummy data
set.seed(123)
df <- data.frame(
  a = sample(1:5, 25, replace=TRUE),
  b = sample(1:5, 25, replace=TRUE),
  c = sample(1:5, 25, replace=TRUE)
)

# Perform clustering
k <- kmeans(df, 3)

# Append id and cluster
dfc <- cbind(df, id=seq(nrow(df)), cluster=k$cluster)

# Add idsort, the id number ordered by cluster 
dfc$idsort <- dfc$id[order(dfc$cluster)]
dfc$idsort <- order(dfc$idsort)

# use reshape2::melt to create data.frame in long format
dfm <- melt(dfc, id.vars=c("id", "idsort"))

ggplot(dfm, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value))
4

1 に答える 1

3

を使用scale_y_continuous()して設定breaks=してから提供できますlabels=(たとえば、文字だけを使用)。expand=c(0,0)内部の引数scale_...を使用すると、プロットの灰色の領域を削除できます。

ggplot(dfm, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value))+
  scale_x_discrete(expand=c(0,0))+
  scale_y_continuous(expand=c(0,0),breaks=1:25,labels=letters[1:25])
于 2013-07-19T18:55:26.757 に答える