我试图在树形图下方的彩条中绘制许多属性,并且无法正确定位(即如何调整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();