ggvis icon indicating copy to clipboard operation
ggvis copied to clipboard

Categorical axis misalignment with reactive data w/ layers_rects

Open jrdnmdhl opened this issue 9 years ago • 1 comments

When a ggvis chart is created using a reactive dataset with a variable number of categories for a categorical axis, rectangles drawn using width=band() as well as height=band() will not line up with the axis ticks properly.

Code for repro is below. To reproduce, run the code, slide the slider to 5 observations and note that rectangles are not aligned with x-axis ticks as you would expect.

library(dplyr)
library(ggvis)
library(shiny)


server <- function(input, output) {
  rData <- reactive(mtcars %>%
                      mutate(name = rownames(mtcars)) %>%
                      head(input$obs))
  rData %>%
    ggvis(~name,~mpg,y2=~0,width=band()) %>%
    layer_rects() %>%
    bind_shiny("plot")
}

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 1, max = 32, value = 100)
    ),
    mainPanel(ggvisOutput("plot"))
  )
)

shinyApp(ui = ui, server = server)

jrdnmdhl avatar Dec 27 '15 18:12 jrdnmdhl

Noticed something else. If you manually drag-resize the ggvis plot after this issue occurs, the plot re-adjusts the axis and alignment is restored.

jrdnmdhl avatar Dec 27 '15 18:12 jrdnmdhl