- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
跟进this question ,我找到了 pheatmap 函数(它为我提供了比 heatmap.2 更多的控制权)。
但是我有两个问题:
1-我无法更改注释(类别)的颜色
2- 即使我将输出保存在 png 文件中,图形窗口也会不断弹出
这是我的 MWE:
library(pheatmap)
library(RColorBrewer)
cols <- colorRampPalette(brewer.pal(9, "Set1"))
mymat <- matrix(rexp(600, 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 = paste("gene", 1:dim(mymat)[1], sep="_"), category = c(rep("CATEGORY_1", 10), rep("CATEGORY_2", 10), rep("CATEGORY_3", 10), rep("CATEGORY_4", 10), rep("CATEGORY_5", 10)))
mycolors <- cols(length(unique(annotdf$category)))
names(mycolors) <- unique(annotdf$category)
mycolors <- list(mycolors = mycolors)
pheatmap(mymat,
color=greenred(75),
scale="row",
cluster_rows = FALSE,
cluster_cols = FALSE,
gaps_row=c(10,20,30,40),
gaps_col=c(3,6,9),
cellheight = 6,
cellwidth = 20,
border_color=NA,
fontsize_row = 6,
main="Genes grouped by categories",
filename = "TEST.png",
annotation_row = annotdf,
annotation_colors = mycolors
)
产生:
正如您所看到的,颜色显然不是我指定的 Set1 调色板,而是默认的 pheatmap 颜色(删除annotation_colors 行您将得到相同的结果)。
所以我的问题是:如何在pheatmap中指定annotation_colors?
另一方面,即使我将 pheatmap 输出保存在 png 文件中,图形窗口也会不断弹出,如何防止这种情况发生?
谢谢!
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
locale:
[1] LC_CTYPE=en_SG.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_SG.UTF-8 LC_COLLATE=en_SG.UTF-8
[5] LC_MONETARY=en_SG.UTF-8 LC_MESSAGES=en_SG.UTF-8
[7] LC_PAPER=en_SG.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gplots_3.0.1 RColorBrewer_1.1-2 pheatmap_1.0.8
loaded via a namespace (and not attached):
[1] compiler_3.3.1 colorspace_1.2-6 scales_0.4.0 plyr_1.8.3
[5] tools_3.3.1 gtable_0.2.0 Rcpp_0.12.7 KernSmooth_2.23-15
[9] gdata_2.17.0 grid_3.3.1 caTools_1.17.1 bitops_1.0-6
[13] munsell_0.4.3 gtools_3.5.0
最佳答案
要为更多类别获取更多颜色,您需要使用不同的调色板。有许多连续的调色板,可以让您远远超过 12 个(例如 RColorBrewer)。
如果您按原样在 MWE 中运行代码,则不应弹出 R 图形窗口。我运行了您的示例,它生成了所需的文件,而无需在控制台上打开图形设备。如果您想进行比较,下面是我的 sessioInfo()
。我会尝试关闭所有设备 (graphics.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
关于R pheatmap : change annotation colors and prevent graphics window from popping up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41628450/
所以下面的内容让我很困惑。 #!/usr/bin/python test = [0, 0, 0, 1, 2, 3, 4, 5, 6] test1 = [0, 0, 0, 1, 2, 3, 4, 5,
这个问题是这个问题的后续问题: deque.popleft() and list.pop(0). Is there performance difference? 在 Python 中,我可以使用 .
我正在使用 bootstrap v2.2.2。我尝试了其他一些方法(即: close popover outside popover but inside stay open 和 How to dis
我正在用 Python 创建提交后脚本并使用子进程调用 git 命令。 在我的脚本中,我想在运行某些命令之前存储所有更改,然后将它们 pop 。问题是,如果没有任何东西可以存储,stash pop 会
我有一个嵌入在 UINavigationController 中的 UITableViewController,我正在尝试将 Peek & Pop 实现到 TableView 中。我的“窥视”部分工作
我的 Windows 机器上安装了 Cygwin、msysgit 和 TortoiseGit。我正在为 Cygwin 编写一个脚本,该脚本通过 ssh 将 git 推送到远程机器: git push
我在 Jenkins 中使用groovy,并且我需要这个字符串来获取其中的最后一个单词。假设字符串是 STATUS = "EXECUTE SIT" 。所以我所做的就是分割字符串,这样我就会得到一个数组
本文是不太具体的问题的后续/重新表述 Is it possible to have a hyperlink inside {content:"..."}? . 用户 Naeem Shaikh ,非常感
Navigator.of(context).pop 和 Navigator.pop(context) 有什么区别? 对我来说两者似乎都在做同样的工作,实际的区别是什么。一个被弃用了吗? 最佳答案 Na
这可能吗?我想要一个更简单的命令来 git stash pop stash@{13} 其中 stash@{13} 只是 last 意思是“最后的存储在列表上”或“最古老的藏品”。 我知道我可以为 gi
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
Visual Studio 2019 中用于 GIT 存储的以下命令有什么区别? 分阶段 pop 和恢复 (--index) 全部 pop 为未暂存状态 使用https://visualstudio.
我想弹出模型的最后一层。所以我使用了 tf.keras.layers.pop(),但它不起作用。 base_model.summary() base_model.layers.pop() base_m
我想使用 navigator.pop 将值从第 2 页传递到第 1 页,并使用 initstate 中的新值刷新或重新加载我的第 1 页或任何其他解决方法? 我能够在第一页中获取这些值,但无法使用 i
pop 函数的文档说: user> (doc pop) ------------------------- clojure.core/pop ([coll]) For a list or queu
我有以下点击处理程序,当点击它时,我从 handsontable 中提取一个数组然后从数组中删除最后一个元素,并将新数组传递给 ajax post。问题是,如果我再次单击该按钮,它将从数组中删除另一个
我在mailmuch中制作了表单并从中获取了代码,我添加到网页并使用href,当用户单击显示弹出窗口时显示表单。没关系 show popup 但是现在我有ajax请求,我希望在ajax返回成功时显示此
我目前正在学习 Python 中的 pop() 函数并有一个问题。 >>> a = [1,2,3,4] >>> a.pop(3) #or a.pop() 4 >>> print(a) [1,2,3]
我目前正在学习 Python 中的 pop() 函数并有一个问题。 >>> a = [1,2,3,4] >>> a.pop(3) #or a.pop() 4 >>> print(a) [1,2,3]
我可以将对象$push编码到Mongo数组上,如下所示: db.foo.update({},{$push:{bar:3}}) 但是我找不到一种语法,可以让我对列表中的最后一项进行$pop编码。 我已经
我是一名优秀的程序员,十分优秀!