我尝试用两种基因型(“rsh 3”和“iron”)差异表达基因的基因本体的-log(FDR)来做热图。在这两列中,“rsh 3”和“iron”写的是GO术语的-log(FDR)。
我不明白是我写错了代码还是我在框架中错误地显示了我的数据。
以防我没说清楚,这是我的框架的样子:
x1c 0d1x的数据
我试了这个代码:
library(ggplot2)
heat <- read_excel("directory/heat_final.xlsx")
heat_matrix <- as.matrix(heat)
ggplot(heat, aes(x = factor(c("rsh3", "iron")), y = GO_term)) +
geom_tile()
字符串
我得到这个错误:
> ggplot(heat, aes(x = factor(c("rsh3", "iron")), y = GO_term)) +
+ geom_tile()
Error in `geom_tile()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (288)
✖ Fix the following mappings: `x`
Run `rlang::last_trace()` to see where the error occurred.
型
实际上,我正在尝试获得一个热图,看起来像本文的图3:
https://www.tandfonline.com/doi/full/10.1080/21580103.2020.1801524
1条答案
按热度按时间gblwokeq1#
您的主要问题是在
ggplot(aes())
中,x
应该是列名称,其中列包含基因型,而不是包含列名称的因子。一个附带说明是,
ggplot()
期望的数据是data.frame,而不是矩阵,所以你的转换充其量是无用的(将立即恢复),或者可能使事情变得更糟。所以,你需要的是一个数据.frame,它有一个列
GO_term
,你可以Map到y
,还有一个列genotype
,你可以Map到x
。当然,还有一个列,你可以Map到fill
颜色,我们叫它log_FDR
。这意味着您需要将对应于基因型的列合并为一列,以使数据为tidy,例如
pivot_longer()
。因此,使用虚拟数据来说明,这里是一个可重复的示例:
字符串