2

デンドログラムの下のカラー バーに多くの属性をプロットしようとしていますが、配置を正しく行うのに問題があります (つまり、y_scale や y_shift を調整する方法)。デフォルトでは、25 個のカラー バーのうち 5 個がプロットされ、y_shift=0.7 に設定すると、すべてのカラー バーが表示されますが、樹状図がカバーされます。

間隔を正しくするために最後の行をどのように変更し、どのように正しい調整を思いついたのだろうかと思っていました。ありがとうございました!

### LIBRARIES #################################################################
library(RColorBrewer);
library(amap);
library(dendextend);

### MADE UP DATA ##############################################################
N <- 200 # number samples
G <- 1000 # number of features
A <- 25 # number of attributes (# color_bars)

# data will make no sense, just for example
data <- matrix(rnorm(G*N,mean=0,sd=1), G, N);
data <- cov(data);
# fake binary attributes 
attributes <- matrix(sample(c(1,2), N*A, replace=TRUE), N, A);

### DENDOGRAM #################################################################
hc <- hcluster(data, method="correlation", link="average");
dend <- as.dendrogram(hc);
dend.idx <- labels(dend);

### COLOR BAR COLORS ##########################################################

# gather enough colors for all of the different attributes
color1 <- list(brewer.pal(12,"Set3"));
color2 <- list(brewer.pal(12, "Paired"));
color3 <- list(brewer.pal(8, "Dark2"));
color <- c(color1[[1]], color2[[1]], color3[[1]]);

# going to bin them all into 4 bins 
n <- 4;

# make A=25 color bars, each with a 4 shades of a single color
color.bar.colors <- NULL; 
for (count in 1:A){
    col.func <- colorRampPalette(c("white", color[count]));
    col.gradient <- col.func(n);
    col.item <- col.gradient[attributes[,count]];
    color.bar.colors <- cbind(color.bar.colors, col.item[dend.idx]);
}

### PLOT ######################################################################

svg("minimal-dend-example.svg", width=100, height = 10);

dend %>% 
    plot(main = "sample");
    colored_bars(
        colors = color.bar.colors, 
        dend = dend, 
        sort_by_labels_order = FALSE,
        # y_shift= 0.7
        );

dev.off();
4

0 に答える 0