[英]drag and zoom scatter plot in highcharts shiny R
我正在尝试创建一个散点图,在其中可以拖动一个区域并在表中查看来自拖动点的数据,以及放大该特定区域。
经过对互联网的研究,我找到了gglopt2的解决方案,该解决方案很好用(接下来介绍)并执行了我描述的所有功能。
现在,我想知道是否可以使用发亮的R上的highcharts包来做同样的事情。我在互联网上进行搜索,但没有找到解决问题的方法。 有人可以帮我吗?
提前致谢
library(ggplot2)
server <- function(input, output, session) {
# global variable, what type of plot interaction
interaction_type <- "click"
# observe for user interaction and change the global interaction_type
# variable
observeEvent(input$user_click, interaction_type <<- "click")
observeEvent(input$user_brush, interaction_type <<- "brush")
observeEvent(input$plot1_dblclick, {
brush <- input$user_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)
} else {
ranges$x <- NULL
ranges$y <- NULL
}
})
output$plot <- renderPlot({
ggplot(mtcars, aes(wt, mpg)) + geom_point()
})
# generate the data to put in the table
dat <- reactive({
user_brush <- input$user_brush
user_click <- input$user_click
if(interaction_type == "brush") res <- brushedPoints(mtcars, user_brush)
if(interaction_type == "click") res <- nearPoints(mtcars, user_click, threshold = 10, maxpoints = 1)
return(res)
})
output$table <- DT::renderDataTable(DT::datatable(dat()[,c("mpg", "cyl", "disp")]))
}
ui <- fluidPage(
h3("Click or brush the plot and it will filter the table"),
plotOutput("plot", click = "user_click", dblclick = "plot1_dblclick", brush = brushOpts( id = "user_brush", resetOnNew = TRUE ) ),
DT::dataTableOutput("table")
)
shinyApp(ui = ui, server = server)
您可以添加一个简单的包装器,该包装器将允许垂直和水平平移。 在轴的afterSetExtremes
事件中,您可以获得当前的极端值,该极端值可以传递到表中以过滤表中的数据。
演示: http : //jsfiddle.net/u9on8dbb/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.