[英]Plotting heatmaps of multiple columns using slider in ggplot R
我有以下數據框
df <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 4),
y = rep(c(1, 2), each = 10),
col1 = rexp(20),
col2 = rnorm(20),
col3 = rexp(20)
)
這就是情節
ggplot(df, aes(x, y, fill = col2)) + geom_tile()
我想制作一個交互式圖表,我可以在其中使用滑塊更改目標列(在第 1、2 和 3 列之間切換)。
提前致謝。
您可以在plotly
的ggplotly
函數中使用frame
美學來制作與您的目標(我不確定您的目標功能是什么)的交互式滑塊,如下所示:
library(plotly)
df <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 4),
y = rep(c(1, 2), each = 10),
col1 = rexp(20),
col2 = rnorm(20),
col3 = rexp(20)
)
df$target <- rep(sample(c(1:3), 2), 10)
plot <- ggplot(df, aes(x, y, fill = col2, frame = target)) + geom_tile()
ggplotly(plot)
輸出:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.