【问题标题】:Animated heatmap in RR中的动画热图
【发布时间】:2018-11-28 15:11:44
【问题描述】:

我正在尝试使用ggplot 和(可能)plot_ly 制作动画热图。到目前为止,我能够完成两个部分目标:

1) 我可以使用plot_ly 制作动画散点图:

dd <- data.frame(f = rep(1:5, c(rep(50, 5))), 
             x = round(runif(250, 10,100),0),
             y = round(runif(250, 10,100),0),
             id = rep(1:50,5)) 

p <- dd %>%
  plot_ly(
    x = ~x,
    y = ~y,
    frame = ~f,
    type = 'scatter',
    mode = 'markers',
    showlegend = F
  )
p

但是,对于scatter,绘图不会传达有关帧内或帧之间重复元素的信息。 (到目前为止,我无法使用带有选项 heatmapplot_ly 工作。)

2) 我可以使用ggplotstat_bin2d 为每个步骤生成热图。

dd.wide <- reshape(dd, direction="wide", timevar = "f")

for (i in seq(2,length(names(dd.wide)),2)){
  p <- ggplot(dd.wide, aes_(x=as.name(names(dd.wide)[i]),y=as.name(names(dd.wide)[i+1]))) +
    stat_bin2d() +
    xlim(10,100) +
    ylim(10,100) +
    guides(fill = guide_colorbar(barwidth = 1, barheight = 5)) +
    scale_fill_gradientn(colours=rev(heat.colors(10)))
  print(p)
}

第二种方法的机器人我没有找到一种简单的方法将这些静态图变成漂亮的动画(我可以制作快照电影,但我希望图像之间的过渡更平滑。)

我也尝试使用ggplotly(),但无法使用。

如果有任何关于如何使热图像plot_ly 中的散点图一样变化的建议,我将不胜感激(我可以使用不同的动画包)。

更新我无法让动画散点图在网站上运行,所以我用绘图的快照替换了动画。

【问题讨论】:

  • 您的保管箱链接已损坏
  • 谢谢你,@camille。不幸的是,我无法在网站上制作动画散点图,所以我用情节的快照替换了动画。

标签: r animation ggplot2 plotly heatmap


【解决方案1】:

您是否正在寻找类似的东西:

p <- ggplot(data= dd, aes(x = x, y = y)) +
  stat_bin2d(aes(frame = f)) +
  xlim(10,100) +
  ylim(10,100) +
  guides(fill = guide_colorbar(barwidth = 1, barheight = 5)) +
  scale_fill_gradientn(colours=rev(heat.colors(10)))
p <- ggplotly(p)

【讨论】:

  • 我试图这样做,但我收到警告 Warning: Ignoring unknown aesthetics: frame 并且输出是静态的。
  • 查看编辑。当我点击播放按钮时有动画。
  • 我没有“播放”按钮,只有带有静态图像的警告。您是否正在使用特定版本的 ggplot
  • 我正在使用plotly_4.7.1.9000 ggplot2_2.2.1.9000
  • 我有 R 3.5.0plotly_4.7.1ggplot2_2.2.1,我使用 RStudio。这会是个问题吗?
猜你喜欢
  • 2021-09-29
  • 1970-01-01
  • 2021-07-24
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
  • 2020-11-02
  • 2011-12-06
相关资源
最近更新 更多