【问题标题】:Plot scatter plot on top of heatmap在热图顶部绘制散点图
【发布时间】:2018-05-04 21:04:19
【问题描述】:

我想在热图上绘制散点图。我用 ggplot 制作了每种类型的图。

散点图:

lambir_t <- ggplot(l_tree, aes(x=xcoord, 
[![enter image description here][1]][1]y=ycoord))+geom_point(col='red')+xlim(c(0, 1040))+ylim(c(0, 500))

热图:

lambir_p <- ggplot(dfo, aes(x,y,
fillz))+geom_tile(color='white')+scale_fill_gradient(low='white', 
high='blue')+labs(x='x', y='y', title='Lambir Hills', 
fill='Phosphorus')

现在我想将散点图放在热图的顶部,这样我就可以看到这些点如何随着磷浓度的变化而变化。关于如何做到这一点的任何想法?

编辑:

@phalteman 的解决方案奏效了。这就是我得到的。我在调整点的大小时遇到​​问题(设置为 1 或 100 时看起来相同),但除此之外这正是我想要的。

【问题讨论】:

标签: r plot ggplot2 plotly


【解决方案1】:

您可以使用不同的数据集向绘图中添加多个图层。像往常一样添加点,但指定数据参数。没有数据很难知道,但这样的事情可能会为您解决问题:

ggplot(dfo, aes(x,y,fillz)) + 
  geom_tile(color='white') + 
  scale_fill_gradient(low='white', high='blue') + 
  labs(x='x', y='y', title='Lambir Hills', fill='Phosphorus') +
  geom_point(data=l_tree, aes(x=xcoord, [![enter image description here][1]][1], y=ycoord)), col='red')

【讨论】:

    【解决方案2】:

    我发现使用相同的数据集,但在每一层中明确表示可以很容易地在图块顶部绘制点。

    颜色按预期工作。 奇怪的是,为所有尺寸设置不同的值时尺寸效果更好

    ggplot(data = mydata, aes(x = baseofheatmap, y = heightofheatmap)) + 
      geom_tile(data = mydata, 
                aes(fill = valuetoheatmap)) +
      geom_point(data = mydata, 
                 aes(x = valuetopoint, 
                     y = heightofheatmap, 
                     size = valuetopoint, 
                     color = "red"))
    

    【讨论】:

      猜你喜欢
      • 2019-06-05
      • 2016-09-10
      • 2022-01-21
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2018-06-03
      相关资源
      最近更新 更多