[英]Plotting heatmaps of multiple columns using slider in ggplot R
I have the following dataframe我有以下数据框
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)
)
And this is the plot这就是情节
ggplot(df, aes(x, y, fill = col2)) + geom_tile()
I want to make an interactive chart where I can use a slider change the target column (switching between column 1, 2 and 3).我想制作一个交互式图表,我可以在其中使用滑块更改目标列(在第 1、2 和 3 列之间切换)。
Thanks in advance.提前致谢。
You can use frame
aesthetic in the ggplotly
function from plotly
to make an interactive slider with your target (I am not sure what your target feature is) like this:您可以在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)
Output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.