要为更多类别获得更多颜色,您将需要使用其他调色板。有许多连续的调色板,使您可以超越12个调色板(例如使用RColorBrewer)。
如果您按原样在MWE中运行代码,则不应弹出R图形窗口。我运行了您的示例,并在不向控制台打开图形设备的情况下生成了所需的文件。sessioInfo()
如果您要比较以下是我的。我将尝试关闭所有设备(dev.off()
,直到收到警告,提示您无法关闭空设备),然后运行热图代码以查看是否可以解决问题。我还将检查以确保您在当前正在使用的目录中具有写权限???
正如@cuttlefish在其评论中所述,要获取自定义的行/颜色,以在颜色列表中显示名称,必须配合colnames
注释数据框的颜色。
mymat <- matrix(rexp(720, rate=.1), ncol=12) colnames(mymat) <- c(rep("treatment_1", 3), rep("treatment_2", 3), rep("treatment_3", 3), rep("treatment_4", 3)) rownames(mymat) <- paste("gene", 1:dim(mymat)[1], sep="_") annotdf <- data.frame(row.names = rownames(mymat), category = rep(paste0("Category_", seq(12)), each=5) ) newCols <- colorRampPalette(grDevices::rainbow(length(unique(annotdf$category)))) mycolors <- newCols(length(unique(annotdf$category))) names(mycolors) <- unique(annotdf$category) mycolors <- list(category = mycolors) pheatmap(mymat, color=greenred(75), scale="row", cluster_rows = FALSE, cluster_cols = FALSE, gaps_row=c(5,10,15,20,25,30,35,40,45,50, 55), gaps_col=c(3,6,9), cellheight = 6, cellwidth = 20, border_color=NA, fontsize_row = 6, main="Genes grouped by categories", filename = "TEST_12cat.png", annotation_row = annotdf, annotation_colors = mycolors )
R version 3.3.0 (2016-05-03) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.6 (El Capitan) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] pheatmap_1.0.8 RColorBrewer_1.1-2 gplots_3.0.1 loaded via a namespace (and not attached): [1] colorspace_1.3-0 scales_0.4.1 colorRamps_2.3 plyr_1.8.4 tools_3.3.0 [6] gtable_0.2.0 Rcpp_0.12.7 KernSmooth_2.23-15 gdata_2.17.0 grid_3.3.0 [11] caTools_1.17.1 munsell_0.4.3 bitops_1.0-6 gtools_3.5.0