我正在尝试使用Rstudio中的Heatmap创建一个热图。
我的数据文件是制表符分隔的文本文件,带有标题行(热图中的行名称),第一列和第二列指示我的热图列名称(我希望这些名称在热图中显示为列标签)
这是我的剧本:
filename <- "Heatmapii.csv"
my_data <- read.table(filename, sep=",", header = TRUE)
#Transform data into a matrix)
my_matrix <- as.matrix(my_data[ ,c(3:23)]) # leave out the first 2 columns
# Save Time column for annotating the heatmap later (1st column)
time_info <- data.frame(time=my_data$Time)
# Save Treatment column for annotating the heatmap later (2nd column)
treatment_info <- data.frame(treatment=my_data$Treatment)
Heatmap(my_matrix)
# Flip rows and columns around
my_matrix <- t(my_matrix)
Heatmap(my_matrix)
colnames(my_matrix) <- my_data$Time
# Create heatmap by showing 1st column names
Heatmap(my_matrix,
show_column_names = TRUE,
cluster_rows =FALSE,
cluster_columns = FALSE,
row_names_side = "left")
# Assign different colors for 2nd column of my_data
treatment.colors <- c("grey","lightblue")
# set the names for treatment.columns
names(treatment.colors) <- paste(c("Control","Inoculated"), sep = "")
Heatmap(my_matrix,
show_column_names = TRUE,
cluster_rows =FALSE,
cluster_columns = FALSE,
row_names_side = "left",
bottom_annotation = HeatmapAnnotation
(treatment_info, col = list(treatment=treatment.colors),
show_legend = TRUE)
因此,基本上,我设法仅将x轴的第二列添加为不同的颜色。我可能想保留不同的颜色,但还要在热图上演示与这些颜色相对应的名称。
我对R很陌生,所以能帮我吗?