我正在寻找从 ggplot 中的一些蛋白质特征数据制作热图,但无法弄清楚如何处理数据框,以便我可以正确地可视化。以下是数据格式的示例:
CellLine, Protein1, Protein2, Protein3, Protein 4
Cancer1, 0.22, 1.15, 0.68, 0.44
Cancer2, 0.95, 1.54, 0.55, 0.02
Cancer3, 1.20, 0.85, 0.99, 0.89
理想情况下,我想在 y 轴上显示细胞系,在 x 轴上显示蛋白质,并在色标中填充相应的表达值。如果您有任何建议,请告诉我,我们将不胜感激!
Ctrls 矩阵化 <- DF from above
CtrlsMatrixed <- ControlsDF %>% pivot_longer(cols = 3:45, cols_vary = "fastest", names_to = "GeneSignature")
代码返回时,pivot_longer() 出现错误 --> 无法组合
CellLine
你可以在 ggplot 中使用
geom_tile
轻松完成此操作
library(tidyverse)
ControlsDF %>%
pivot_longer(-CellLine, names_to = 'Protein', values_to = 'Expression') %>%
ggplot(aes(Protein, CellLine, fill = Expression)) +
geom_tile(color = 'black') +
scale_fill_viridis_c() +
coord_equal(expand = FALSE)
创建于 2023-09-12,使用 reprex v2.0.2
问题中的数据采用可重现的格式
ControlsDF <- structure(list(CellLine = c("Cancer1", "Cancer2", "Cancer3"),
Protein1 = c(0.22, 0.95, 1.2), Protein2 = c(1.15, 1.54, 0.85
), Protein3 = c(0.68, 0.55, 0.99), Protein4 = c(0.44, 0.02,
0.89)), class = "data.frame", row.names = c(NA, -3L))