1

I have been playing around with plotOutput("plot_click") in Shiny. It seems pretty straightforward in most plots. Rather than returning the pixel x and pixel y value for a mouse click, it returns the x and y value scaled to the plot of interest for a mouse click. A app.R example is below -

library(shiny)

ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    qplot(mtcars$wt, mtcars$mpg)
  })

  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}

shinyApp(ui, server)

I would like to extend upon this functionality so that I can obtain the x and y value scaled to a subplot of interest for a mouse click. I am interested in this when working with plot matrices. An app.R example is below -

library(shiny)

ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)

server <- function(input, output) {
  data <- select(mtcars,wt,mpg,qsec)

  output$plot1 <- renderPlot({
    ggpairs(data)
  })

  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}

shinyApp(ui, server)

I am only interested in the bottom-left three subplots. When I mouse click at any area of these bottom-left three subplots, however, I get the x and y values scaled for the entire plot. Is it possible to change this so that I could get the values for the x and y values scaled for each subplot accurately? Note: I am not interested in any points outside of these three bottom left subplots, and would not care to loose their interactive functionality if needed. Please kindly share any ideas!

  • I don't think it's possible to get coordinates specific to a subplot. But if you are interested in the raw data of those subplots, consider plotly. This question provides an almost-identical example as yours. http://stackoverflow.com/q/41409890/4718512 – oshun Jan 14 '17 at 17:46
  • Many thanks. However, I am not considering plotly because I am interested in *all* x and y values scaled for the subplots (not just the ones that happen to be in the data). –  Jan 14 '17 at 18:24

0 Answers0