Description
Brushing points within shiny apps depends on the output of ggplot2::summarise_layout(p)
CRAN ggplot2 3.0.0 works as expected.
With changes from #2832 , the range values of CoordTrans
where changed to map back to their original values. While I agree with the intent, ggplot2::summarise_layout uses the range values to calculate the returned domain value.
library(ggplot2);
dat <- data.frame(xvar = c(10^-1, 10^3), yvar = c(2^-2, 2^4))
p <- ggplot(dat, aes(xvar, yvar)) + geom_point() +
scale_x_log10(expand = c(0 ,0)) +
scale_y_continuous(expand = c(0, 0)) +
coord_trans(y = "log2")
p
Created on 2018-09-17 by the reprex package (v0.2.0).
With v3.0.0 the fully transformed scale values provide:
ggplot2::summarise_layout(ggplot2::ggplot_build(p))
#> # A tibble: 1 x 10
#> panel row col vars xmin xmax ymin ymax xscale yscale
#> <fct> <dbl> <dbl> <list> <dbl> <dbl> <dbl> <dbl> <list> <list>
#> 1 1 1 1 <list … -1 3 -2 4 <S3: ScaleCo… <S3: ScaleCo…
With current github version the fully transformed scale values provide:
# create `p` again
ggplot2::summarise_layout(ggplot2::ggplot_build(p))
#> # A tibble: 1 x 10
#> panel row col vars xmin xmax ymin ymax xscale yscale
#> <fct> <dbl> <dbl> <list> <dbl> <dbl> <dbl> <dbl> <list> <list>
#> 1 1 1 1 <list … -1 3 0.25 16 <S3: ScaleCo… <S3: ScaleCo…
The ymin
and ymax
are displaying the original values, not the fully transformed values.
Shiny demo... Try selecting the two points at x = 150
. In the dev version, select the very bottom of the plot (around y = 2
) are at x = 150
to brush the transformed data locations.
library(ggplot2)
library(shiny)
ui <- fluidPage(plotOutput("plot", brush = "brush"), tableOutput("table"))
server <- function(input, output, session) {
output$plot <- renderPlot({
ggplot(mtcars, aes(hp, wt)) + geom_point() +
coord_trans(y = "log2")
})
output$table <- renderTable({
brushedPoints(mtcars, input$brush)
})
}
shinyApp(ui, server)