0
我正在嘗試創建散點圖,在該散點圖中,我可以拖動區域並在表格中查看拖動點中的數據以及放大該特定區。拖拽和放大散點圖在高亮有光澤R
經過對互聯網的研究,我找到了一個gglopt2的解決方案,該解決方案很好(接下來介紹)並執行我描述的所有功能。
現在我想知道是否可以使用highcharts包上閃亮的R做同樣的事情。我在互聯網上搜索,但我發現沒有解決我的問題。有人可以幫助我嗎?
在此先感謝
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)