R pheatmap()条件分组中的小故障以及其他混淆点
我想在为DGE制作的热图上标注我的状况。 此代码:R pheatmap()条件分组中的小故障以及其他混淆点,r,pheatmap,R,Pheatmap,我想在为DGE制作的热图上标注我的状况。 此代码: mat <- assay(rld)[topVarGenes,] condition = c("black", "orange") names(condition) = c("Dark", "Light") ann_colors = list(condition = condition) pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")
mat <- assay(rld)[topVarGenes,]
condition = c("black", "orange")
names(condition) = c("Dark", "Light")
ann_colors = list(condition = condition)
pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(24), annotation_colors = ann_colors[1], border_color = "grey60", fontsize = 12, scale = "row")
产生以下错误:
转换注释时出错(注释颜色、注释颜色):
可变条件下的系数级别与注释颜色不匹配
最后,我尝试了我在堆栈溢出帖子中找到的这段代码来定义注释,它让R使用正确的颜色,但它们的顺序与条件不符,因为%%2==0导致它将每隔一个样本标记为“light”,但我想不出还有什么其他方法。代码如下:
pheatmap(mat, annotation = annotation, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(24), annotation_colors = ann_colors, border_color = "grey60", fontsize = 12, scale = "row")
annotation <- data.frame(condition = factor(1:6 %% 2==0, labels = c("Dark", "Light")))
annotation在vignette中不太清楚,但您可以按照以下步骤生成正确的data.frame和list,没有理由不工作:
首先,我制作了一个类似于您的矩阵:
library(pheatmap)
M = cbind(matrix(runif(30,min=0,max=0.5),ncol=3),
matrix(runif(30,min=0.3,max=0.8),ncol=3))
rownames(M) = paste0("row",1:10)
colnames(M) = paste0("sample",1:6)
假设前3列为“亮”,后3列为“暗”。为此,我们创建一个data.frame,重要的是让行名与矩阵的列名匹配:
ann_column = data.frame(
condition = rep(c("light","dark"),each=3))
rownames(ann_col) = colnames(M)
ann_column
condition
1 light
2 light
3 light
4 dark
5 dark
6 dark
现在,对于颜色,您需要一个列表,名称需要与上面的数据框相匹配,在灯光内部,您需要指定与什么颜色匹配的因子,因此:
ann_colors = list(condition = c(dark="black",light="orange"))
我们得出:
pheatmap(M,annotation_col=ann_col,annotation_colors=ann_colors)
嘿,欢迎来到SO。我已经修改了你的问题,将图像嵌入为合适的图像。您可以通过编辑器中的“图像”按钮执行此操作。希望这有帮助
pheatmap(M,annotation_col=ann_col,annotation_colors=ann_colors)