我正在尝试创建一个散点图,在该散点图中我可以拖动一个区域并在表格中查看拖动点的数据以及放大该特定区域。
在互联网上进行研究之后,我找到了一个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)