ggplot mouse

Published by onesixx on

Theme

https://onesixx.com/hrbrthemes/
library('hrbrthemes')

data %>% ggplot(aes(x,y)) + geom_line() +
           theme_ipsum(base_size=9) +
           labs(x="x", y="y")

ggsave("sixxplot.png", 
  width=16, height=16, units="cm", type="cairo")

Mouse click dblclick brush hover

https://stackoverflow.com/questions/30527977/ggplot2-how-to-differentiate-click-from-brush

library(shiny)
library(ggplot2)

runApp(shinyApp(
  ui = fluidPage(
    plotOutput("plot", click = "click", brush = "brush", dblclick = "dClick")
  ),
  server = function(input, output, session) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(wt, mpg)) + geom_point()
    })
    observeEvent(input$brush, {
      cat("brushed
")
    })
    observeEvent(input$click, {
      cat("clicked
")
    })
    observeEvent(input$dClick, {
      cat("Doublie clicked
")
    })
  }
))

library(shiny)
library(ggplot2)

ui <- fluidPage(
    plotOutput("plot", width="100%",height="600px",
                click=clickOpts(id="click"),
                hover=hoverOpts(id="hover"),
                brush=brushOpts(id="brush"),
                dblclick=dblclickOpts(id="dblclick")
    )
)
server <- function(input, output, session) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(wt, mpg)) + geom_point()
    })
    
    observeEvent(input$click, {
      cat("
 clicked 
")
    })
    observeEvent(input$hover, {
      cat("hovered---")
    })  
    observeEvent(input$brush, {
      cat("
 brushed
")
    })    
    observeEvent(input$dblclick, {
      cat("
 DBLClicked 
")
    })
}
shinyApp(ui, server)

library(shiny)
library(ggplot2)

ui <- fluidPage(
  plotOutput("plot", width="100%",height="600px",
             click=clickOpts(id="click"),
             hover=hoverOpts(id="hover"),
             brush=brushOpts(id="brush"),
             dblclick=dblclickOpts(id="dblclick")
  ),
  verbatimTextOutput("click"),
  verbatimTextOutput("hover"),
  verbatimTextOutput("brush"),
  verbatimTextOutput("dblclick")
)
server <- function(input, output, session) {
  output$plot <- renderPlot({
    ggplot(mtcars, aes(wt, mpg)) + geom_point()
  })
  output$click <- renderText({
    Mclick <- reactive({input$click})
    Mc <- Mclick()
    paste0("click:",Mc,"
")
  })
  output$hover <- renderText({
    Mhover <- reactive({input$hover})
    Mh <- Mhover()
    paste0("hover:",Mh,"
")
  })
  output$brush <- renderText({
    Mbrush <- reactive({input$brush})
    Mb <- Mbrush()
    paste0("brush:",Mb,"
")
  })
  output$dblclick <- renderText({
    Mdblclick <- reactive(input$dblclick)
    Md <- Mdblclick()
    paste0("dblclick:",Md,"
")
  })
}
shinyApp(ui, server)

Categories: R ggplot2

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x