nearPoints() with geom_tile() in ggplot2

45 views
Skip to first unread message

Peter N.

unread,
Sep 28, 2016, 10:51:01 PM9/28/16
to Shiny - Web Framework for R
Does nearPoints() work with geom_tile()? I get wrong coordinates when I use it. It mostly shows for lowest xvar and highest xvar.

Important parts of my server functions are like:
output$plotTile <- renderPlot(
    {
    p=ggplot(dataset.tile(), aes(x = Year, y = CountryName ,fill=log10(Value),tooltip=Value))
    p=p+geom_tile()+ theme_minimal()+theme(axis.text = element_text(size = 8), axis.title.y=element_blank())
    p=p+scale_fill_continuous(name=expression(paste(Log[10],"P")), low="blue", high="red")
    p=p+facet_grid(RegionName~.,scales="free_y",space="free", labeller=labeller(RegionName=strTxt))+coord_cartesian()
    p
    },height=750);
 
  output$my_tooltip <- renderPrint({
    verbatimTextOutput("vals")
  })
 
  output$vals <- renderText({
    hover <-input$plotTile_hover
    #hover$x=10.2 #(hover$x)/10+9
    #hover$y=15
    y <- nearPoints(df=icsyData,coordinfo=hover,)[,c("Year","CountryName","Value")]
    print(hover)
    req(nrow(y) != 0);
    t=paste(as.character(y$Year), as.character(y$CountryName), y$Value,collapse=" ")
    t
  })


Important parts of my ui.R is like:
  fluidRow(
    column(8,offset=0, div(style="position:absolute,max-width:400px,border:10px",plotOutput("plotTile",hover="plotTile_hover",height = "750px"),uiOutput("my_tooltip"))),
    column(width=4,
            fluidRow(
             column(12,offset=0,div(style="max-width:100px, border: 10px solid #DCDCDC",h5("Top producer in each region (available data)")))
           )
           )
  )


Thanks in advance!
Reply all
Reply to author
Forward
0 new messages