在 R 中绘制与矢量场重叠的热图?

问题描述 投票:0回答:1

我目前正在绘制给定数据的热图。我的数据集有 5 列(x、y、relative_frequecy、vx、vy)。热图的填充由相对频率给出,而 vx 和 vy 分别是来自点 (x,y) 的向量的 x 和 y 分量。

我尝试过使用,

plot <- ggplot(Protein_Quasipotentials, aes(x = G_Atot, y = G_Btot)) + 
        geom_tile(aes(fill = Relative_Frequency)) + 
        theme_classic() + coord_fixed() + geom_abline(slope=1, intercept=0) +
        xlab("Protein A") + ylab("Protein B") +
        scale_x_continuous(expand=c(0,0), limits=c(-1, 3000)) + scale_y_continuous(expand=c(0,0), limits=c(-1, 3000)) +
        scale_fill_gradientn( limits=range(0,40), breaks=c(0.0, 10.0, 20.0, 30.0, 40.0), colors=c("darkorange","chocolate1", "yellow", "chartreuse2","chartreuse3")) +
        theme(panel.background = element_rect(fill="cadetblue3")) +
        geom_segment(aes(xend = G_Atot + vA_N, yend = G_Btot + vB_N ), arrow = arrow(length=unit(0.1, "cm")), size = 0.1)

但不幸的是,矢量场的分辨率太高并且模糊了数据。因此,我想减少数据点来绘制矢量场,而不是相对频率。我只看到了可以降低相对频率的方法。

r ggplot2
1个回答
0
投票

您可以向

x
提供不同的数据框架以及不同的
y
geom_segment
美学,这将覆盖您提供给
ggplot
的数据框架。创建一个新的数据框,该数据框是原始数据框,但分辨率降低。像这样向
geom_segment
提供数据和美学(注意
data
参数以及
x
y
美学):

geom_segment(
  data = WhateverYouCallYourNewDataFrame,
  aes(x = G_Atot, y = G_Btot, xend = G_Atot + vA_N, yend = G_Btot + vB_N),
  arrow = arrow(length=unit(0.1, "cm")),
  size = 0.1
)
© www.soinside.com 2019 - 2024. All rights reserved.