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