R中的两个变量之间的交互式散点图,而无需使用闪亮
是否可以在R中的两个变量(用户从多个变量中选择)之间创建一个交互式散点图,而无需使用Shiny。一个示例是在这里使用Shiny。是否可以在不使用闪亮的情况下制作这种交互式图?(例如,使用rmarkDown)
在这里使用一个按钮使用plotly上的按钮选择一个变量:
library(plotly)
df <- data.frame(x = 1:5, y = 7:11, z = 10:14)
create_buttons <- function(df, y_axis_var_names) {
lapply(
y_axis_var_names,
FUN = function(var_name, df) {
button <- list(
method = 'restyle',
args = list('y'
, list(df[, var_name]))
, label = sprintf('Show %s', var_name)
)
},
df
)
}
y_axis_var_names <- colnames(df)
p <- plot_ly(df, x = ~x, y = ~y, mode = "markers", name = "A", visible = T) %>%
layout(
title = "Drop down menus - Styling",
xaxis = list(title = "x"),
yaxis = list(title = "y"),
updatemenus = list(
list(
y = 0.7,
buttons = create_buttons(df, y_axis_var_names)
)
))
p
但是我不知道如何在第二个按钮添加第二个按钮多变的!
Is it possible to create an interactive scatter plot between two variables (selected by user from multiple variables) in R, without using shiny. An example is here using shiny. Is it possible to make such interactive plot without using shiny?(For example using Rmarkdown)
An example is here that use one button to select a variable using a button on plotly:
library(plotly)
df <- data.frame(x = 1:5, y = 7:11, z = 10:14)
create_buttons <- function(df, y_axis_var_names) {
lapply(
y_axis_var_names,
FUN = function(var_name, df) {
button <- list(
method = 'restyle',
args = list('y'
, list(df[, var_name]))
, label = sprintf('Show %s', var_name)
)
},
df
)
}
y_axis_var_names <- colnames(df)
p <- plot_ly(df, x = ~x, y = ~y, mode = "markers", name = "A", visible = T) %>%
layout(
title = "Drop down menus - Styling",
xaxis = list(title = "x"),
yaxis = list(title = "y"),
updatemenus = list(
list(
y = 0.7,
buttons = create_buttons(df, y_axis_var_names)
)
))
p
But I do not know how to add a second button to the second variable!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论