R pheatmap确定列顺序

huangapple go评论141阅读模式
英文:

R pheatmap determine column order

问题

Hi Stack Overflow community,

我正在使用pheatmap()创建热图,并在对列进行排序时遇到困难。我的数据 'matrix' 已经按照所需的顺序排序,以便在绘图中显示。

我尝试将我的所需顺序(升序)保存到 'col_order' 中,并在pheatmap()中使用 'column_order = col_order' 作为选项。然而,它没有起作用。我还尝试设置 'cluster_cols = F',但R返回错误消息 'formal argument "cluster_cols" matched by multiple actual arguments'。

我感激任何评论!

以下是我的代码:

pheatmap(matrix,
         annotation_row=groupmatrix,
         cluster_cols = T,
         color = colorRampPalette(c("blue", "white", "red"))(50),
         show_colnames = T,
         scale="row",  
         border_color="NA",
         fontsize = 8,
         fontsize_row = 6,
         fontsize_col = 6,
         treeheight_row = 0,
         treeheight_col = 0, # 移除树状图
         cluster_rows = F,
         cluster_cols = F)

这是我目前的图表外观,x轴的顺序混乱,我希望它按照从1到48的顺序排列。

R pheatmap确定列顺序

英文:

Hi Stack Overflow community,

I am creating heatmap using pheatmap() and have difficulty ordering columns in a sorted order. My data 'matrix' is already sorted in the desired order for display on the plot.

I tried save my desired order (ascending order) into 'col_order' and use 'column_order = col_order' as an option in pheatmap(). However, it doesn't work. I also tried set 'cluster_cols = F' but R returns error message 'formal argument "cluster_cols" matched by multiple actual arguments'

I appreciate any comment!

Here is my code:

pheatmap(matrix,
         annotation_row=groupmatrix,
         cluster_cols = T,
         color = colorRampPalette(c("blue", "white", "red"))(50),
         show_colnames = T,
         scale="row",  
         border_color ="NA",
         fontsize =8,
         fontsize_row=6,
         fontsize_col=6,
         treeheight_row = 0,
         treeheight_col = 0, # remove dendrogram
         cluster_rows = F,
         cluster_cols = F)

Here is what my plot looks like right now, the x-axis order is all mess up and I want it to go from 1 to 48 in order.

R pheatmap确定列顺序

答案1

得分: 1

尝试这个:在第三行中去除 cluster_cols = TRUE

这里是一个示例:

library(pheatmap)

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

pheatmap(test,
         color = colorRampPalette(c("blue", "white", "red"))(50),
         show_colnames = T,
         scale="row",
         border_color = "NA",
         fontsize = 8,
         fontsize_row = 6,
         fontsize_col = 6,
         treeheight_row = 0,
         treeheight_col = 0, # 移除树状图
         cluster_rows = F,
         cluster_cols = F)

R pheatmap确定列顺序

英文:

Try this:
Remove the cluster_cols = TRUE in the third row:

Here is an example:

library(pheatmap)

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")


pheatmap(test,
         color = colorRampPalette(c("blue", "white", "red"))(50),
         show_colnames = T,
         scale="row",  
         border_color ="NA",
         fontsize =8,
         fontsize_row=6,
         fontsize_col=6,
         treeheight_row = 0,
         treeheight_col = 0, # remove dendrogram
         cluster_rows = F,
         cluster_cols = F)

R pheatmap确定列顺序

huangapple
  • 本文由 发表于 2023年2月19日 06:19:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定