无法在热图上获取正确的 x 轴标签

Trouble getting proper labels for x-axis on heatmap

目前在格式化某些基因表达数据的热图时遇到一些问题。我想要样本的标签,而不仅仅是样本 1、样本 2 等。另外,希望热图对 50 个不同的基因使用随机样本,而不仅仅是前 50 个。代码和数据集链接如下.

library(dplyr)
library(tidyr)
library(ggplot2)

set.seed(1234)

nci <- read.csv('/Users/KyleHammerberg/Desktop/ML Extra Credit/nci.datanames.csv')

# create matrix
mat <- matrix(rexp(3200, rate=1), ncol=64)
rownames(mat) <- paste0('gene',1:nrow(mat))
colnames(mat) <- paste0('sample',1:ncol(mat))
mat[1:10,1:10]

# convert to data.frame and gather
mat <- as.data.frame(mat)
mat$gene <- rownames(mat)
mat <- mat %>% gather(key='sample', value='value', -gene)

ggplot(mat, aes(sample, gene)) + geom_tile(aes(fill=value)) + theme(axis.text.x = element_text(angle=90, size = 4),
                                                                                  axis.text.y = element_text(size = 4))

数据:https://github.com/khammerberg53/MLEC/blob/main/nci.datanames.csv

也许这会有所帮助:

library(tidyverse)
nci %>%
  rename(gene = X) %>%
  pivot_longer(-gene, names_to = "sample", values_to = "value") %>%
  filter(gene %in% sample(unique(gene),50)) %>% 
ggplot(aes(x = sample, y = gene, fill = value)) +
  geom_tile() +
  theme(axis.text.x = element_text(angle=90, size = 4),
        axis.text.y = element_text(size = 4))    

数据

nci <- read.csv("https://raw.githubusercontent.com/khammerberg53/MLEC/main/nci.datanames.csv")