修改以下代码,只展示热图的一半:df <- read_excel("Merge_18.UMAP_celltypes_num_type.xlsx", sheet = "Proportion") df # 仅选择数值型的列 numeric_columns <- sapply(df, is.numeric) df_numeric <- df[, numeric_columns] # 计算斯皮尔曼相关系数 spearman_corr <- cor(df_numeric, method = "spearman") # 保留两位小数的相关系数 formatted_corr <- format(round(spearman_corr, 2), nsmall = 2) # 绘制斯皮尔曼相关系数热图 pdf("Merge_18.UMAP_celltypes_num_type_spearman_corr_heatmap.pdf", width = 8, height = 8) heatmap.2(spearman_corr, trace = "none", col = colorRampPalette(c("#FFFFFF","#F8FCCB", "#FCA86B"))(100), cellnote = formatted_corr, notecol = "black") dev.off()
时间: 2024-04-23 08:28:45 浏览: 113
two-phase-merge_sort-.rar_2phase merge sort_merge_sort_two merge
5星 · 资源好评率100%
要修改代码以展示热图的一半,你可以使用以下代码:
```R
df <- read_excel("Merge_18.UMAP_celltypes_num_type.xlsx", sheet = "Proportion")
df_numeric <- df\[, sapply(df, is.numeric)\]
spearman_corr <- cor(df_numeric, method = "spearman")
formatted_corr <- format(round(spearman_corr, 2), nsmall = 2)
half_spearman_corr <- spearman_corr\[1:(ncol(spearman_corr)/2), \]
half_formatted_corr <- formatted_corr\[1:(ncol(formatted_corr)/2), \]
pdf("Merge_18.UMAP_celltypes_num_type_spearman_corr_heatmap.pdf", width = 8, height = 8)
heatmap.2(half_spearman_corr, trace = "none", col = colorRampPalette(c("#FFFFFF","#F8FCCB", "#FCA86B"))(100),
cellnote = half_formatted_corr, notecol = "black")
dev.off()
```
这段代码首先读取Excel文件中的数据,并选择数值型的列。然后计算斯皮尔曼相关系数,并保留两位小数的相关系数。接下来,我们将相关系数矩阵的一半提取出来,以便只展示热图的一半。最后,使用`heatmap.2`函数绘制热图,并将结果保存为PDF文件。
#### 引用[.reference_title]
- *1* *2* *3* [小鼠参考基因组id转换gtf文件chb 自己注释 从官网下载相应的基因中注释文件gse155802 getmatrix genecode](https://blog.csdn.net/qq_52813185/article/details/127760873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文