我有两个矩阵,A 和 B,我想用 plotly 制作两个热图,并将它们覆盖
library(plotly)
A = matrix(c(1:8, rep(0, 8)), ncol = 4)
B = matrix(c(rep(0, 8), 1:8), ncol = 4)
PA <- plot_ly(z = A, type = "heatmap", colors = colorRamp(c("white", "green")))
PB <- plot_ly(z = B, type = "heatmap", colors = colorRamp(c("white", "red")))
当我尝试覆盖它们时,它们确实被夸大了,但第二个热图完全掩盖了第一个。
PA %>% add_trace(z = B, type = "heatmap")
我可以改变不透明度以“看到”两个热图
PA %>% add_trace(z = B, opacity = 0.5, type = "heatmap")
但它真的不漂亮,我不能为每个热图设置不同的颜色。
有没有像下面的例子那样覆盖它们的优雅方法?多谢。
p = plot_ly(x = rnorm(500), opacity = 0.6, type = "histogram") %>%
add_trace(x = rnorm(500)+1) %>%
layout(barmode="overlay")