我正在尝试在闪亮的应用程序中使用自定义coord_trans和brushedPoints,但有些方法却无法正常工作。我可以在log2转换下刷点。但是,当我尝试使用自定义坐标变换时,刷不起作用。我粘贴了以下代码:
library(ggplot2)
shinyApp(
ui = fluidPage(
selectInput(inputId = 'axis_trans',
label = 'Transform Axis: ',
choices = list("None", "log2", "asinh")
),
plotOutput("bPlot", brush=brushOpts("bBrush")),
fluidRow( column(5, "Brushed: ", verbatimTextOutput( "brushed" )))
),
server = function(input, output, session) {
asinhco_trans <- function(cofactor=10) {
require(scales)
trans_new("asinhco",
transform=function(x) {
if (cofactor !=0) {
xt <- asinh(x/cofactor)
} else {
xt <- asinh(x)
}
return(xt)
},
inverse= function(xt) {
if (cofactor != 0) {
x <- cofactor*sinh(xt)
} else {
x <- sinh(xt)
}
return(x)
}
)
}
output$bPlot <- renderPlot({
p <- ggplot( mtcars, aes_string( x="mpg", y="wt") ) + geom_point()
if (input$axis_trans == "asinh") {
p <- p + coord_trans(x=asinhco_trans(), y = asinhco_trans())
}
if (input$axis_trans == "log2") {
p <- p + coord_trans(x="log2", y="log2")
}
return(p)
})
output$brushed <- renderText({
nrow(brushedPoints(mtcars,input$bBrush))
})
}
)